`

jQuery单击记录行自动选中checkbox

阅读更多

 $(".list tr").slice(1).each(function(){ 
    var p = this; 
    $(this).children().slice(1).click(function(){ 
        $($(p).children()[0]).children().each(function(){ 
            if(this.type=="checkbox"){ 
                if(!this.checked){ 
                    this.checked = true; 
                }else{ 
                    this.checked = false; 
                } 
            } 
        }); 
    }); 
});
 
 $(function () {
            //除了表头(第一行)以外所有的行添加click事件.
            $("tr").first().nextAll().click(function () {
                //为点击的这一行切换样式bgRed里的代码:background-color:#FF0000;
                $(this).children().toggleClass("bgRed");
                //判断td标记的背景颜色和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);
                }
            });
       });

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics