列印預覽關倍訓傳到原來的模態框,關閉按鈕不能使用,求大佬幫幫忙



uj5u.com熱心網友回復:
自頂自頂自頂uj5u.com熱心網友回復:
function doPrint3(){
//判斷iframe是否存在,不存在則創建iframe
var iframe=document.getElementById("print-iframe");
if(!iframe){
var el = document.getElementById("printcontent");
iframe = document.createElement('IFRAME');
var doc = null;
iframe.setAttribute("id", "print-iframe");
iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
//這里可以自定義樣式
//doc.write("<LINK rel="stylesheet" type="text/css" href="https://bbs.csdn.net/topics/css/print.css">");
doc.write('<div>' + el.innerHTML + '</div>');
doc.close();
iframe.contentWindow.focus();
}
iframe.contentWindow.print();
if (navigator.userAgent.indexOf("MSIE") > 0){
document.body.removeChild(iframe);
}
}用上面的實作列印頁面部分內容
uj5u.com熱心網友回復:
沒點《列印》前, 點這《關閉》能關閉嗎?uj5u.com熱心網友回復:
可以的uj5u.com熱心網友回復:
您好,我用這個方法打出來的沒有表格的框線uj5u.com熱心網友回復:
那是因為列印時 window.document.body.innerHTML = bdhtml 這個陳述句
bdhtml若含有腳本,innerHTML重新賦值時,這個腳本是失效的,網上有很多解決方案,一般是找出腳本刪掉再重新賦值,以下函式可供參考(如果有多個腳本,要改下函式)
function regen_script(obj){
var oScript = obj.getElementsByTagName('script')[0];
if(!empty(oScript)){
obj.removeChild(oScript);
var newScript = document.createElement('script');
newScript.type='text/javascript';
newScript.innerHTML = oScript.innerHTML;
obj.appendChild(newScript);
}
}
regen_script(window.document.body);
你也可用2樓的方案列印,注意css要和母本一樣,否則列印效果不一樣
uj5u.com熱心網友回復:
您好,我用這個方法打出來的沒有表格的框線
function doPrint3(){
//判斷iframe是否存在,不存在則創建iframe
var iframe=document.getElementById("print-iframe");
if(!iframe){
var el = document.getElementById("printcontent");
iframe = document.createElement('IFRAME');
var doc = null;
iframe.setAttribute("id", "print-iframe");
iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
//這里可以自定義樣式
//doc.write("<LINK rel="stylesheet" type="text/css" href="https://bbs.csdn.net/topics/css/print.css">");
doc.write('<div>' + el.innerHTML + '</div>');
doc.close();
iframe.contentWindow.focus();
}
iframe.contentWindow.print();
if (navigator.userAgent.indexOf("MSIE") > 0){
document.body.removeChild(iframe);
}
}
用上面的實作列印頁面部分內容
把表格的border樣式寫成行內樣式試試。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/125245.html
標籤:JavaScript
上一篇:js陣列和字串方法
下一篇:請教xslt的一個例子
