问题描述
我正在寻找一种在打印功能上添加参数的方法,因为我只需要打印表格,当我提醒表格时它会显示正确的值但是当我打印时会打印整个页面。
I am looking for a way to add parameters on a print function, because I have to print only the table and when I alert the table it shows me the correct value but when I'm printing it prints the entire page.
我的代码是
aa = document.getElementById('tablename').innerHTML
如果我 alert(aa)
它给了我写入值
然后我 print(aa)
它给了我整个页面。
所以我尝试了 print(aa)
和 aa.print
,但它不起作用。
If I alert(aa)
it gives me the write valuethen I print(aa)
it give me the entire page.so I tried print(aa)
and aa.print
and it doesn't work.
有没有人知道这方面的解决方案?
Does anyone know the solution for this?
推荐答案
打印样式表很不错,但你仍然可以在Javascript中完成此任务。只需将您的值传递给以下函数...
Print stylesheets are nice, but you can still accomplish this in Javascript. Just pass your value to be printed to the following function...
function printIt(printThis) {
var win = window.open();
self.focus();
win.document.open();
win.document.write('<'+'html'+'><'+'body'+'>');
win.document.write(printThis);
win.document.write('<'+'/body'+'><'+'/html'+'>');
win.document.close();
win.print();
win.close();
}
这篇关于你可以在javascript中的print()函数中添加参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!