一、假設有如下一段html代碼
<dd id="1"> <input id="checkbox-518" class="imagezz" name type="checkbox" value="518"> </dd>
選中事件(根據選中情況修改上一層背景):
var $test_image_check_box_click = function() { if ($(this).attr("checked") == "checked") { $(this).parent().css({"background":"#dcf4fc"}); } else { $(this).parent().css({"background":"#fcf7c7"}); } check_all_imagezz(); }
綁定事件:
$(#checkbox-518).click($test_image_check_box_click);
二、假設html中有很多並列的dd標簽,每個dd標簽中有一個checkbox,class名都為imagezz,對於每個checkbox都綁定事先設定的$test_image_check_box_click事件
$(document).ready(function(){ $(".imagezz").click($test_image_check_box_click); }
推薦一個自己業余時間開發的網盤搜索引擎,360盤搜(www.360panso.com)