<!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 的区别
原创
©著作权归作者所有:来自51CTO博客作者qq5c322e67bf4c9的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
jquery attr和prop区别 attr选中checkbox不起作用
M和js对
jquery checkbox js对象 共享数据 -
jquery中attr和prop的区别
jquery中attr和prop的区别
jquery中attr和prop的区别 -
attr和prop区别
是否可见 是否可见
html 自定义 jquery