首页 > 编程 > JavaScript > 正文

ie中js创建checkbox默认选中问题探讨

2019-11-20 21:51:58
字体:
来源:转载
供稿:网友
测试浏览器:ie8(兼容和不兼容模式),ff6。
复制代码 代码如下:

var chk = document.createElement("input");
chk.setAttribute("type","checkbox");
container.appendChild(chk);
chk.setAttribute("checked",true);

以上代码在ie8兼容模式和ff6下都没有总是,但在ie8不兼容模式下不起作用,只有在appendChild后,再设置checked的值就都起作用,如下:
复制代码 代码如下:

var chk = document.createElement("input");
chk.setAttribute("type","checkbox");
chk.setAttribute("checked",true);
container.appendChild(chk);

貌似以上这段话反了。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表