`attr(’checked’,false)`不在IE6上工作

正如标题所说,我无法使用.attr('checked', false)来处理IE6。 我正在克隆一些HTML,然后在将新克隆的HTML分配给一个元素之前,我运行它并取消检查新克隆部分中的所有复选框,这在除IE 6之外的所有浏览器中都能正常工作。

这是代码:

  //give each input and select a custom id clone.find('input, select').each( function( i ) { //get the id attribute var id = $(this).attr('id'); //uncheck all of the tick boxes $(this).attr('checked', ''); //get the name attribute var name = $(this).attr('name'); $(this).attr('name', name+"_"+count) $(this).attr('id', id+"_"+count+"_"+i) }); //append the newly created area to the area wrapper clone.appendTo('[data-custom="area_wrapper"]'); 

有什么方法可以解决这个问题吗?

尝试

 .removeAttr("checked") 

最简单的解决方案也是优化:

 this.checked = false; 

实际上,您可以将此优化应用于所有代码:

  //get the id attribute var id = this.id; //uncheck all of the tick boxes this.checked = false; //get the name attribute var name = this.name; this.name = name+"_"+count; this.id = id+"_"+count+"_"+i; 

这是因为底层的jQuery代码无论如何都会访问这些属性( attr主要直接使用属性直到jQuery 1.6)。

有关详细信息,请访问http://whattheheadsaid.com/2010/10/utilizing-the-awesome-power-of-jquery-to-access-properties-of-an-element 。

没有HTML属性’checked = false’,只有’checked = checked’表示已选中的复选框,没有取消选中复选框。

使用.removeAttr('checked');