廢話不多說,直接上代碼吧
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>JqueryTest</title> <script src="js/jquery-1.8.3.min.js"></script> <script> $(document).ready(function () { $('input').click(function(e){ e.stopPropagation(); var parent = $(this).parent(); $(this).is(':checked') ? parent.css('background-color','#CCC') : parent.css('background-color','#FFF'); }); $('div').click(function(){ $(this).find(':checkbox').click(); if($(this).css('background-color') == 'rgb(255, 255, 255)'){ $(this).css('background-color', '#CCC'); }else{ $(this).css('background-color', '#FFF'); } }); }); </script></head><body> <div> <input type="checkbox" />A </div> <div> <input type="checkbox" />B </div> <div> <input type="checkbox" />C </div></body></html>效果截圖:

以上這篇jQuery實(shí)現(xiàn)點(diǎn)擊DIV同時(shí)點(diǎn)擊CheckBox,并為DIV上背景色的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注