实例 jQuery prop() 与 attr() 方法的不同点

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#p1").html("attr('checked'): " + $("input").attr('checked')
    + "<br>prop('checked'): " + $("input").prop('checked'));
  });
});
</script>
</head>
<body>
<p><b>Note:</b> Check and uncheck the checkbox and then click the button to refresh content.</p>
<button>Check value of attr() and prop()</button>
<br><br>
<input id="check1" type="checkbox" checked="checked">
<label for="check1">Check me</label>
<p id="p1">
</body>
</html>
                    

输出结果