首页 > Web开发 > 详细

JQuery - CheckBox Prop 和 attr 的区别

时间:2020-05-05 13:20:16      阅读:64      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CheckBox Prop 和 attr 的区别</title>
  </head>
  <body>
    <input type="text" />
    <label>选中 <input type="checkbox" checked /></label>
    <script src="./jquery-3.4.1.min.js"></script>
    <script src="./jquery-migrate-1.2.1.js"></script>
    <script>
      $("input[type=checkbox]").bind("change", function () {
        console.log($(this).attr("checked")); // 返回 undefined 或 checked
        console.log($(this).prop("checked")); // 返回 true 或 false
      });
    </script>
  </body>
</html>

 

JQuery - CheckBox Prop 和 attr 的区别

原文:https://www.cnblogs.com/500m/p/12830273.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!