最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery 實(shí)現(xiàn)checkbox全選,反選,全不選等功能代碼(奇數(shù))

 更新時(shí)間:2012年10月24日 10:55:56   作者:  
jquery 實(shí)現(xiàn)全選,反選,全不選等功能,下面直接以例子進(jìn)行說明,需要的朋友可以參考下
設(shè)頁面有如下一組復(fù)選框和幾個(gè)相關(guān)按鈕(全選,反選,全不選等):
復(fù)制代碼 代碼如下:

<input type="checkbox" name="fruit" value="apple" />蘋果
<input type="checkbox" name="fruit" value="orange" />橘子
<input type="checkbox" name="fruit" value="banana" />香蕉
<input type="checkbox" name="fruit" value="grape" />葡萄
<input type="button" id="btn1" value="全選">
<input type="button" id="btn2" value="全不選">
<input type="button" id="btn3" value="反選">
<input type="button" id="btn4" value="選中所有奇數(shù)">
<input type="button" id="btn5" value="獲得選中的所有值">

則分別實(shí)現(xiàn)相關(guān)功能的完整代碼如下:
復(fù)制代碼 代碼如下:

$(function(){
$('#btn1').click(function(){//全選
$("[name='fruit']").attr('checked','true');
});
$('#btn2').click(function(){//全不選
$("[name='fruit']").removeAttr('checked');
});
$('#btn3').click(function(){//反選
$("[name='fruit']").each(function(){
if($(this).attr('checked')){
$(this).removeAttr('checked');
}else{
$(this).attr('checked','true');
}
})
});
$("#btn4").click(function(){//選中所有奇數(shù)
$("[name='fruit']:even").attr('checked','true');
})
$("#btn5").click(function(){//獲取所有選中的選項(xiàng)的值
var checkVal='';
$("[name='fruit'][checked]").each(function(){
checkVal+=$(this).val()+',';
})
alert(checkVal);
})
});

注意使用 jquery 之前必須要引入 jquery 包哦!

相關(guān)文章

最新評(píng)論

唐海县| 武定县| 禄丰县| 通城县| 怀化市| 保康县| 宁津县| 正安县| 廊坊市| 诏安县| 油尖旺区| 海盐县| 隆尧县| 丰都县| 连江县| 清河县| 沁水县| 綦江县| 无极县| 周口市| 大足县| 宁乡县| 白银市| 金华市| 尉氏县| 靖宇县| 东丰县| 溧水县| 明光市| 阜南县| 大厂| 望城县| 齐齐哈尔市| 郎溪县| 安义县| 九江县| 克什克腾旗| 漳州市| 剑河县| 长沙县| 韩城市|