我有這樣的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