正如标题所说,我无法开始.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"]');
Run Code Online (Sandbox Code Playgroud)
有什么方法可以解决这个问题吗?
最简单的解决方案也是优化:
this.checked = false;
Run Code Online (Sandbox Code Playgroud)
实际上,您可以将此优化应用于所有代码:
//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;
Run Code Online (Sandbox Code Playgroud)
这是因为底层的jQuery代码无论如何都会访问这些属性(attr
大多数直接使用属性直到jQuery 1.6).
有关此内容的更多信息,请访问http://whattheheadsaid.com/2010/10/utilizing-the-awesome-power-of-jquery-to-access-properties-of-an-element.
归档时间: |
|
查看次数: |
5254 次 |
最近记录: |