在javascript里动态添加一行后(行里有个html控件)
因为在动态添加后,页面不会刷新(目的就是实现无刷新)
所以源代码里是没有添加上去的行(包括里的控件)的代码
因此无法用document.getElementById("新添加的行中的控件ID")获取新添加的行里的控件在网上找的方法:
table.rows[新行索引].cells[0].childNode[0]
依然无效请问各位有什么好的解决方法没?
因为在动态添加后,页面不会刷新(目的就是实现无刷新)
所以源代码里是没有添加上去的行(包括里的控件)的代码
因此无法用document.getElementById("新添加的行中的控件ID")获取新添加的行里的控件在网上找的方法:
table.rows[新行索引].cells[0].childNode[0]
依然无效请问各位有什么好的解决方法没?
var newTd = newTr.insertCell();
newTd.innerHTML="<input type="radio" id="r1"/>";在不刷新情况下,再用document.getElementById("r1").checked取不到
table.rows[新行索引].cells[0].getElementsByTagName("input")[0].checked试试?
var newTd = newTr.insertCell();
var rad = document.createElement("input");
rad.type = "radio";
rad.id = "r1";
newTd.appendChild(rad);alert(document.getElementById("r1").checked);
正解用 getElementsByTagName