丢失整个DOM DOM运行javascript [英] Losing entire page DOM running javascript
问题描述
这个问题从这个问题继续下去:
This question continues on from this question:
我的最新代码是:
$(document).ready(function () {
var oScript = document.createElement('script');
oScript.type = 'text/javascript';
oScript.src = 'converter.js';
// most browsers
oScript.onload = function () {
$('#converter #form').load(renderConverter());
}
// IE
oScript.onreadystatechange = function () {
if (this.readyState == 'complete') {
$('#converter #form').load(renderConverter());
}
}
document.body.appendChild(oScript);
});
问题在 .load(renderConverter());
。这是什么,它删除整个DOM并打印什么renderConverter();请求打印。
The issue is on .load(renderConverter());
. What this does is, it removes the entire DOM and prints what renderConverter(); asks it to print.
函数 renderConverter();
使用以下内容打印html:
The function renderConverter();
uses the following to print the html:
window.document.write(html);
我更改为:
document.write(html)
但它也是一样的。
如何强制它只能在div中打印我已经运行回调了? div是 #converter #form
。
How can I force it to only print within the div I have run the call back on?. The div being #converter #form
.
推荐答案
code> document.write 在页面加载完成后。
You cannot use document.write
after the page has finished loading.
您应该使用jQuery DOM操作。
You should use jQuery DOM manipulation instead.
这篇关于丢失整个DOM DOM运行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!