我用了兩種方法,如下:都沒有實作,卻也沒有報錯,請大佬看看
function print(){
debugger;
var iframeLength = document.getElementsByTagName("iframe").length;
var iframe_start = 0;
$('iframe').each(function () {
var src = $(this).attr('src');
$(this).onload = function () {
iframe_start++;
console.info(iframe_start);
if (iframe_start == iframeLength) {
window.print();
}
}
});
}
function print2() {
debugger;
var iframes = document.getElementsByTagName("iframe");
for (var i = 0; i < iframes.length; i++) {
var iframeId = iframes[i].id;
var currentIframe = document.getElementById(iframeId);
if (currentIframe.attachEvent) {
currentIframe.attachEvent("onload", function () {
// 等待iframe加載完成
});
continue;
} else {
currentIframe.onload = function () {
window.print();// iframe加載完成
}
}
}
}
uj5u.com熱心網友回復:
function print(){debugger;
var iframeLength = document.getElementsByTagName("iframe").length;
var iframe_start = 0;
$('iframe').each(function () {
var src = $(this).attr('src');
/*$(this).ready(function () {
iframe_start++;
console.log(iframe_start,'iframe_start');
if (iframe_start == iframeLength) {
window.print();
}
})*/
// 此處錯誤 jq中使用ready
$(this).onload = function () {
iframe_start++;
console.info(iframe_start);
if (iframe_start == iframeLength) {
window.print();
}
}
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/262307.html
標籤:JavaScript
上一篇:取URL的值(js檔案)
下一篇:使用npm安裝依賴時 出現的問題
