JS新手~请指教我写了一个在线流程图的编辑网页,流程图画完后,使用window.print(),将选定区域打印出来。
但是执行打印后,网页就不能任何操作了,任何的动作都不能完成。以下是我的程序,请问会是什么问题呢?function functionPrint(){
$("#printPDF").click(function(){
bdhtml = window.document.body.innerHTML;
sprnstr = "<!--startprint-->";
eprnstr = "<!--endprint-->";
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
window.document.body.innerHTML = bdhtml;
return 0 ;
})
};
addLoadEvent(functionPrint); //这是把functionPrint()函数添加到window.onload()事件中。其中"<!--startprint-->"和"<!--endprint-->"我添加到了要打印部分的开头和结束了。
但是执行打印后,网页就不能任何操作了,任何的动作都不能完成。以下是我的程序,请问会是什么问题呢?function functionPrint(){
$("#printPDF").click(function(){
bdhtml = window.document.body.innerHTML;
sprnstr = "<!--startprint-->";
eprnstr = "<!--endprint-->";
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
window.document.body.innerHTML = bdhtml;
return 0 ;
})
};
addLoadEvent(functionPrint); //这是把functionPrint()函数添加到window.onload()事件中。其中"<!--startprint-->"和"<!--endprint-->"我添加到了要打印部分的开头和结束了。
个人感觉是网页内容重新赋值自后js事件绑定无效了
window.document.body.innerHTML= prnhtml
你这个做法是不对的,
参考我的方法吧:js打印页面区域的应用方法