开发者

insert text so i can .print()

I have a field called exp delivery date so i need the user to put a date in 开发者_开发技巧and then press print. However the print function doesn't catch the inputted text. So i did this:

$('#exp').live('change',function(){         
                var deliv = $('#exp').val();
                $('#delivDate').replaceWith("<p id='delivDate'>" + deliv + "</p>");
                $('#exp').val('');
            }); 

'#exp' is the input id and '#delivDate' is a <p> tag right next to the input. I'm only doing this so the .print() will catch it?

Can anyone think of a better way to do this? (it doesn't work in IE but does in FF by the way)


Another way to accomplish this might be to use a jQuery plugin called Print Element which is able to print any specific element existing in the DOM. Or all of it.


If have trouble figuring out the mechanics on how to make the inputted text printable then here's a sample:

<textarea id="exp"></textarea>
<p id="delivDate"></p>

<script type="text/javascript">
$('#exp').live('change',function(){          
    var deliv = $('#exp').val();
    $('#exp').css('display', 'none'); // optional
    $('#delivDate').text(deliv);
    $('#exp').val(''); 
});
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜