jquery获取input的checked属性

1.经常需要判断某个按钮是否被选中。

2.基于jquery。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>checked</title>
</head>
<body>
<input id="box" type="checkbox" checked>

<script src="./jquery-3.1.1.min.js"></script>
<script>
    $("#box").on("click",function(){
//        console.log($("#box").attr("checked"))
        if($(this).is(":checked")){
            console.log("yes")
        }
    })
    
  
</script>
</body>
</html>

 

posted @ 2017-08-02 22:46  橙云生  阅读(5149)  评论(0编辑  收藏  举报