Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript。。文件。写。。奇怪的文档行为:';(_Javascript_Document.write - Fatal编程技术网

JavaScript。。文件。写。。奇怪的文档行为:';(

JavaScript。。文件。写。。奇怪的文档行为:';(,javascript,document.write,Javascript,Document.write,我有一些非常奇怪的行为:(我希望有人能帮我 使用xmlhttp请求,我得到一个带有document.write的javascript文件,它看起来像这样: document.write("<input type='hidden' name='orange' value='17' />"); document.write("<input type='hidden' name='apple' value='29' />"); document.write(“”); 文件。

我有一些非常奇怪的行为:(我希望有人能帮我

使用xmlhttp请求,我得到一个带有document.write的javascript文件,它看起来像这样:

document.write("<input type='hidden' name='orange' value='17' />");
document.write("<input type='hidden' name='apple' value='29' />"); 
document.write(“”);
文件。填写(“”);
我基本上希望在iframe中的表单中添加这些输入元素

// i get the document of the iframe
var docc = doc.getElementById("rs-iframe").contentDocument;
var body = docc.getElementsByTagName('body')[0];

// i put the response from xmlhttprequest in a script tag
var script = docc.createElement('script');
script.type = "text/javascript"; 
script.text = "//<![CDATA["+xmlhttp.responseText+"//]]>";

// i get the position where i want to put my script tag
var elem = form.getElementsByTagName('script')[6];  

// i try to insert my script tag from xmlhttprequest before the script i retrieve from the form
elem.parentNode.insertBefore(script, elem);

// the i append the form to the body of the iframe document                      
body.appendChild(form);
//我得到iframe的文档
var docc=doc.getElementById(“rs iframe”).contentDocument;
var body=docc.getElementsByTagName('body')[0];
//我将来自xmlhttprequest的响应放在一个脚本标记中
var script=docc.createElement('script');
script.type=“text/javascript”;
script.text=“/”;
//我得到了要放置脚本标记的位置
var elem=form.getElementsByTagName('script')[6];
//我尝试在从表单检索脚本之前插入xmlhttprequest中的脚本标记
elem.parentNode.insertBefore(脚本,elem);
//我将表单附加到iframe文档的主体中
子体(形式);
现在,当我尝试获取
doc.getElementsByTagName('input');
时,我只获取从document.write添加的元素,其他表单元素已消失:(

感谢您的帮助。

这就是
write()
所做的,它写入文档中。如果文档已经关闭(关闭意味着完全加载),write()将覆盖该文档

解决方案很简单:当文档已经加载时,不要使用write()。使用诸如appendChild()或insertBefore()之类的DOM方法来注入新节点。

这就是
write()
所做的,它在文档中写入。如果文档已经关闭(关闭意味着完全加载),则write()将覆盖文档

解决方案很简单:当文档已经加载时,不要使用write()。使用诸如appendChild()或insertBefore()之类的DOM方法来注入新节点