Javascript 通过分配动态变量,document.getElementById()
我在html表中使用该表td中输入字段的id动态创建行。 使用新添加的行和输入框id正确创建的表也已创建。但当我尝试使用id获取该输入框时,它会引发null异常Javascript 通过分配动态变量,document.getElementById(),javascript,html,Javascript,Html,我在html表中使用该表td中输入字段的id动态创建行。 使用新添加的行和输入框id正确创建的表也已创建。但当我尝试使用id获取该输入框时,它会引发null异常 var cell1 = row.insertCell(1); var element1 = document.createElement("input"); element1.name = rId + "_" + rowCount + "_newscheduledate"; element1.id = rId + "_"
var cell1 = row.insertCell(1);
var element1 = document.createElement("input");
element1.name = rId + "_" + rowCount + "_newscheduledate";
element1.id = rId + "_" + rowCount + "_newschedueldate";
cell1.appendChild(element1);
alert(rowCount+" : "+rId); //here alert shows the values
var tt = document.getElementById(rId + '_' + rowCount + '_newscheduledate');
alert(tt); // here null comes
例外情况如下所示
Error: document.getElementById(rId + ("_" + rowCount + "_newscheduledate")) is null
更改:-
element1.id = rId + "_" + rowCount + "_newschedueldate";
到
你的英语有拼写错误 element1.id=rId+“”+行数+“newschedueldate” 需要
element1.id=rId+““+行计数+“newscheduledate” 很抱歉,我没有发现这两行代码之间有任何区别。请帮我澄清一下。
element1.id = rId + "_" + rowCount + "_newscheduledate";