欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery中checkbox全選失效的解決方法

 更新時(shí)間:2014年12月26日 12:54:36   投稿:mdxy-dxy  
這篇文章主要介紹了jquery中checkbox全選失效的解決方法,需要的朋友可以參考下

如果你使用jQuery 1.6 ,代碼if ( $(elem).attr(“checked”) ),將獲得一個(gè)屬性(attribute) ,它不改變該復(fù)選框被選中和選中。它只是用來存儲默認(rèn)或選中屬性的初始值。為了保持向后兼容,.attr() 方法從 jQuery 1.6.1+ 開始除了返回屬性值外,還會更新 property 屬性,因此 boolean attribute(布爾屬性)不需要通過 .prop() 來改變其值。推薦使用上述方法之一,來取得 checked 的值。

使用jQuery的attr方法獲取和設(shè)置復(fù)選框的”checked”屬性,發(fā)現(xiàn)第一次全選/取消全選有效,之后就無效了,但查看html源文件,復(fù)選框?qū)傩源_實(shí)已經(jīng)被更新了,就是頁面中沒有更新,正確的方法如下:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script><script type="text/javascript">// <![CDATA[
$(function(){
$('.ckAll').click(function(){
$(".box-items").each(function(){
  $(this).prop("checked",!!$(".box-all").prop("checked"));
});
});
});
// ]]></script>
<div><label class="ckAll"><input class="box-all" type="checkbox" /><span>全選</span></label>
<input class="box-items" type="checkbox" />
<input class="box-items" type="checkbox" />
<input class="box-items" type="checkbox" />
<input class="box-items" type="checkbox" />
<input class="box-items" type="checkbox" />
</div>

相關(guān)文章

最新評論