Jon*_*atz 1 javascript ajax innerhtml appendchild
我有一个脚本,用于在按下当前输入字段元素时添加输入字段元素。当我使用innerHTML时,它会替换当前的,这不是我想要的。所以我认为appendChild应该添加而不是替换,但它不起作用。这是我的脚本..
<script type="text/javascript">
function addfile()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("org_div1").appendChild = xmlhttp.responseText;
}
}
xmlhttp.open("GET","addfile.php");
xmlhttp.send();
}
</script>
Run Code Online (Sandbox Code Playgroud)
还有我的 html 内容..
<div id="org_div1" class="file_wrapper_input">
<input type="hidden" value="1" id="theValue" />
<input type="file" class="fileupload" name="file1" size=
"80" onchange="addfile()" /></div>
Run Code Online (Sandbox Code Playgroud)
还有我的 addfile.php 文件..
var i=0;
var ni = document.getElementById('org_div1');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
var divIdName = num;
</script>
<input type="file" class="fileupload" size="80" name="file' + (num) + '" onchange="addfile()" />;
Run Code Online (Sandbox Code Playgroud)
有什么意见吗?同样,innerHTML 可以工作,appendChild 则不能。谢谢。
Parent.appendChild() 是一个等待 DomNode 对象的函数,并且您正在传递一个字符串,它无法工作......
尝试 :
var d = document.createElement('div');
d.innerHtml = xmlhttp.responseText;
document.getElementById("org_div1").appendChild(d);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3052 次 |
| 最近记录: |