我的问题是这样的
在一个页面上动态生成checkbox,比如做权限功能选取的时候。
有两种这样的情况:
1.有多个checkbox时,我用js事件去获取当前checkbox没有问题
2.当动态生成的checkbox只有一个时(指的是当前页面只生成一个checkbox,不是只选中一个),不管我用getElementsByName还是getElementById都不能正确获取到checkbox,并报js undefined错误
寻求各位网友支援?
代码
var newInput = document.createElement("input");
newInput.type="checkbox";
newInput.name=id2;
newInput.value=CusNo;
newLi.appendChild(newInput);
在一个页面上动态生成checkbox,比如做权限功能选取的时候。
有两种这样的情况:
1.有多个checkbox时,我用js事件去获取当前checkbox没有问题
2.当动态生成的checkbox只有一个时(指的是当前页面只生成一个checkbox,不是只选中一个),不管我用getElementsByName还是getElementById都不能正确获取到checkbox,并报js undefined错误
寻求各位网友支援?
代码
var newInput = document.createElement("input");
newInput.type="checkbox";
newInput.name=id2;
newInput.value=CusNo;
newLi.appendChild(newInput);
newInput.setAttribute('type', 'checkbox');
newInput.setAttribute('value', 'CusNo');
newInput.setAttribute('name', 'id2');
newLi.appendChild(newInput);
看这样行不行?