[英]Javascript error when creating form elements
Error:错误:
uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLSelectElement.appendChild]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame:: http://localhost/midas/index.php/submit/displayform :: :: line 104" data: no]未捕获的异常:[异常...“组件返回失败代码:0x80004003(NS_ERROR_INVALID_POINTER)[nsIDOMHTMLSelectElement.appendChild]”nsresult:“0x80004003(NS_ERROR_INVALID_POINTER)”位置:“JS 框架:: http://localhost/midas/index.php。 /submit/displayform :: :: line 104" data: no]
The code is meant to create:该代码旨在创建:
textboxt - textbox - textbox - pulldown - textbox文本框 - 文本框 - 文本框 - 下拉 - 文本框
Here is the code below这是下面的代码
<script type="text/javascript">
<!--
var ta=new Array();
var n=15;
window.onload=function()
{
inp=document.getElementsByTagName('input');
for(c=0;c<inp.length;c++)
{
if(inp[c].value=='add')
{
inp[c].onclick=function()
{
var ta = [];
var n = 15;
ta[n]=document.createElement('input');
ta[n].setAttribute('rows',1);
ta[n].setAttribute('cols',20);
ta[n].name='time'+n;
document.getElementById('txtara').appendChild(ta[n])
ta[n]=document.createElement('input');
ta[n].setAttribute('rows',1);
ta[n].setAttribute('cols',20);
ta[n].name='event'+n;
document.getElementById('txtara').appendChild(ta[n])
ta[n]=document.createElement('input');
ta[n].setAttribute('rows',1);
ta[n].setAttribute('cols',20);
ta[n].name='supplies'+n;
document.getElementById('txtara').appendChild(ta[n])
var sel = document.createElement('select');
ta[n]=document.createElement('option');
ta[n].value = 'YES';
ta[n].name='success'+n;
ta[n].innerHTML = ta[n].value;
n++;
ta[n]=document.createElement('option');
ta[n].value = 'NO';
ta[n].name='success'+n;
ta[n].innerHTML = ta[n].value;
n++;
sel.appendChild(ta[0]);
sel.appendChild(ta[1]);
document.getElementById('txtara').appendChild(sel);
document.getElementById('here').appendChild(sel);
document.getElementById('txtara').appendChild(ta[n])
n++;
}
}
}
}
//-->
</script>
Your code is creating nodes and storing them in ta[15]
and ta[16]
, but you're inserting nodes from ta[0]
and ta[1]
into the DOM, which don't exist.您的代码正在创建节点并将它们存储在ta[15]
和ta[16]
中,但是您将ta[0]
和ta[1]
中的节点插入到不存在的 DOM 中。
do var n = 0
;做var n = 0
; instead of n = 15
.而不是n = 15
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.