IE7中javascript操作CheckBox的checked=true不打勾的解决方法

复制代码 代码如下:

  var chkbox = document.createElement("INPUT");

  chkbox.type = "checkbox";

  chkbox.checked=true;

  lnk.parentNode.appendChild(chkbox);

  以上代码在IE7下,生成的Checkbox无法正确的打上勾。

  原因是 chkbox控件还没初始化(appendChild),就开始操作它的结果

  据此将代码改为即可正确显示:

  

复制代码 代码如下:

  var chkbox = document.createElement("INPUT");

  chkbox.type = "checkbox";

  lnk.parentNode.appendChild(chkbox);

  chkbox.checked=true;