jQuery prop() 方法

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>
原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/6534461.html