1.方法简介
prop() 方法设置或返回被选元素的属性和值。
2.方法示例
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="checkbox" id="ck" />全选
<br /><br />
<input type="checkbox" class="ck" />
<input type="checkbox" class="ck" />
<input type="checkbox" class="ck" />
<input type="checkbox" class="ck" />
<input type="checkbox" class="ck" />
</body>
</html>
<script type="text/javascript" src="js/jquery.min.js" > </script>
<script>
//添加事件的方法:
$("#ck").click(function(){
//找到自身的选种状态
//$(this)筛选本身,自身
$(".ck").prop("checked",$(this).prop("checked"));
//找到所有的$(".ck"),设置属性:.prop("checked",属性既是上面的自身状态)!
})
//找到ck;.click代表点击事件,没有方法的方法名=匿名函数
</script>
本文介绍如何使用jQuery的prop()方法来控制页面上多个复选框的状态,通过一个全选按钮来同步更新一组复选框的选中状态。
1825

被折叠的 条评论
为什么被折叠?



