我试图根据我在父窗口中的值在子窗口中动态创建元素,但没有成功。子窗口正在打开,但没有打开元素。这是我写的代码,可以吗一个请有一个战利品吗?这可能完全使用 javascript/jquery>
function fnOpenPrint(){
openPrint = window.open('print.htm');
childWin = openPrint.document;
var newDiv = childWin.createElement("<div id='para'>")
newDiv.innerHTML = document.forms[0].txtBranch.value;
}
最佳答案
尝试
function fnOpenPrint(){
var openPrint = window.open('print.htm');
openPrint.onload = function() {
var doc = openPrint.document;
var newDiv = doc.createElement("div");
newDiv.id = 'para';
newDiv.innerHTML = document.forms[0].txtBranch.value;
doc.body.appendChild(newDiv);
};
}
子窗口中的 DOM 操作必须在完成加载后完成。
关于javascript - 如何从父窗口在子窗口中动态创建元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3989149/