jq 监听checkbox
2022-09-19 14:00:47 来源:admin 点击:542
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<script>
$(document).ready(function(){
$("input[name='category']").each(function() {
var currentEle = $(this);
currentEle.click(function() {
console.log(currentEle.val());
console.log(currentEle.is(":checked"))
});
});
});
</script>
</head>
<body>
<div id="zfx">
<p><input type="checkbox" name="category" value="今日话题" />今日话题 </p>
<p><input type="checkbox" name="category" value="视觉焦点" />视觉焦点</p>
<p><input type="checkbox" name="category" value="财经" />财经</p>
<p><input type="checkbox" name="category" value="汽车" />汽车</p>
<p><input type="checkbox" name="category" value="科技" />科技</p>
<p><input type="checkbox" name="category" value="房产" />房产</p>
<p><input type="checkbox" name="category" value="旅游" />旅游</p>
</div>
</body>
</html>