JQuery點(diǎn)擊行tr實(shí)現(xiàn)checkBox選中的簡(jiǎn)單實(shí)例

字號(hào):


    下面小編就為大家?guī)?lái)一篇JQuery點(diǎn)擊行tr實(shí)現(xiàn)checkBox選中的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。
    代碼如下:
    $(function () {
       //除了表頭(第一行)以外所有的行添加click事件.
       $("tr").first().nextAll().click(function () {
        //為點(diǎn)擊的這一行切換樣式bgRed里的代碼:background-color:#FF0000;
        $(this).children().toggleClass("bgRed");
        //判斷td標(biāo)記的背景顏色和body的背景顏色是否相同;
        if ($(this).children().css("background-color") != $(document.body).css("background-color")) {
         //如果相同,CheckBox.checked=true;
         $(this).children().first().children().attr("checked", true);
        } else {
         //如果不同,CheckBox.checked=false;
         $(this).children().first().children().attr("checked", false);
        }
       });
      });
    以上這篇JQuery點(diǎn)擊行tr實(shí)現(xiàn)checkBox選中的簡(jiǎn)單實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考