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

jquery處理checkbox(復(fù)選框)是否被選中實(shí)例代碼

 更新時(shí)間:2017年06月12日 10:50:38   作者:sdusdu  
這篇文章主要介紹了jquery處理checkbox(復(fù)選框)是否被選中實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下

jquery處理checkbox(復(fù)選框)是否被選中

現(xiàn)在如果一個(gè)復(fù)選框被選中,是用checked=true,checked="checked"也行

要用prop代替attr會(huì)更好,雖然在jQuery1.6之前版本的attr()方法能正常使用,但是現(xiàn)在必須使用prop()方法代替

 實(shí)例代碼:

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8"/>
<title>checkbox</title>
</head>
<body>

<input type="button" id="btn1" value="全選">
<input type="button" id="btn2" value="取消全選">
<input type="button" id="btn3" value="選中所有奇數(shù)">
<input type="button" id="btn4" value="反選">
<input type="button" id="btn5" value="獲得選中的所有值">

<input type="checkbox" value="checkbox1"/>
<input type="checkbox" value="checkbox2"/>
<input type="checkbox" value="checkbox3"/>
<input type="checkbox" value="checkbox4"/>
<input type="checkbox" value="checkbox5"/>

<script src="js/jquery-3.2.0.min.js"></script>
<script>
$(function(){

var checkbox = $("input[type=checkbox]");

$("#btn1").on("click",function(){
checkbox.prop("checked",true);
});

$("#btn2").on("click",function(){
checkbox.prop("checked",false);
});

$("#btn3").on("click",function(){
$("input[type=checkbox]:even").prop("checked",true);
});

$("#btn4").on("click",function(){
checkbox.each(function(){
if($(this).prop("checked")){
$(this).prop("checked",false);
}else{
$(this).prop("checked",true);
}
});
});

$("#btn5").on("click",function(){
var str = "";
$("input[type=checkbox]").each(function(){
if($(this).prop("checked")){
str += $(this).val() + ",";
}

});
console.log(str);
});

});
</script>


</body>
</html>

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論

宜都市| 句容市| 河北区| 井陉县| 洛隆县| 兴化市| 察哈| 青河县| 如东县| 平塘县| 玉门市| 临湘市| 迭部县| 会理县| 韶关市| 上虞市| 武宁县| 新野县| 南平市| 炉霍县| 浠水县| 大连市| 南陵县| 五寨县| 屯昌县| 禹州市| 福建省| 和静县| 遂平县| 察哈| 华阴市| 榆林市| 阿拉善右旗| 崇州市| 武川县| 宝山区| 富阳市| 梅州市| 云梦县| 伊川县| 蒙自县|