我有这样的HTML:覆盖jQuery的。点击事件
<style>
div.icons {
background-color:red;
width:100px;
height:100px;
float:left;
margin-right:10px;
}
</style>
<div class="icons"><input type="checkbox" checked="checked" />Box 1</div>
<div class="icons"><input type="checkbox" checked="checked" />Box 2</div>
<div class="icons"><input type="checkbox" checked="checked" />Box 3</div>
而这个jQuery ...
<script>
$(document).ready(function() {
$("div.icons").click(
function(){
if ($(this).children("input").is(":checked")) {
$(this).css("background-color","yellow");
$(this).children("input").attr('checked', false);
} else {
$(this).css("background-color","red");
$(this).children("input").attr('checked', true);
}
}
);
});
</script>
当我点击一个div,jQuery的改变的背景颜色该div并取消选中它的内部输入。但是当我点击div内的输入复选框时,它不会检查输入框。
当点击复选框时,有没有办法覆盖$("div.icons").click
?还是有更好的方法来做到这一点?
不错,谢谢! – supercoolville 2011-12-17 06:25:50