jquery操作checked

  jquery操作checkbox,如何获取勾选状态?如何使得勾选?如何取消勾选?

来段代码就知道了:

<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
   <input type="checkbox" id="abc" ><label for="abc">CHECKBOX</label>
   <hr/>
   <button value="点击" id="btn">CHANGE IT</button>
</body>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $(function(){
    $('#btn').click(function(){
       var check = $('#abc'),
           ischeck = check.is(':checked');// 检查是否被checked
       if(ischeck){
          check.removeAttr('checked');// 取消勾选
       }else {
          check.prop('checked','checked');// 使得勾选
       }
    });
  });
</script>
</html>

 

-

 
posted @ 2015-06-15 11:53  根号五  阅读(353)  评论(0编辑  收藏  举报