插入文本以便我可以 .print()
我有一个名为到期交货日期
的字段,因此我需要用户输入日期,然后按打印。但是打印功能无法捕获输入的文本。所以我这样做了:
$('#exp').live('change',function(){
var deliv = $('#exp').val();
$('#delivDate').replaceWith("<p id='delivDate'>" + deliv + "</p>");
$('#exp').val('');
});
“#exp”是输入 id,“#delivDate”是输入旁边的
标记。我这样做只是为了让
.print()
能够捕获它?
有人能想出更好的方法来做到这一点吗? (顺便说一下,它在 IE 中不起作用,但在 FF 中起作用)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现此目的的另一种方法可能是使用名为 Print Element 它能够打印 DOM 中存在的任何特定元素。或者全部。
如果无法弄清楚如何使输入的文本可打印的机制,那么这里有一个示例:
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: