English 中文(简体)
如果电池重复
原标题:Highlight table row if cell duplicate

我的表格如下:

Checkbox (ID)  |  Training Course Code  |  Training Course Name  |  ....
   [ ]         |  DE00155115-1          |  H&S Exec 1            |  ....
   [ ]         |  DE00155115-1          |  H&S Exec 1            |  ....
   [ ]         |  DE00074454-2          |  H&S Exec 2            |  ....

每门课程都不止一次,但只有这样,才可以选择每门课程的多重身份。

我想要做的是,一旦选定了重复浏览器,就可以失控/突出重复浏览。

在上述例子中,如果选择了第一行,第二行就会失控,反之亦然。 如果选择第三行的话,不会发生。

我曾尝试过几次使用 j子的功能,但并不真正确定从哪里开始建设。

最佳回答

选择:

$( table )
    .on( click , input:checkbox ,
        function(){
            var that = $(this),
                thatRow = that.closest( tr ),
                id = that.parent().next( td ).text();

            if (that.is( :checked )){
                that
                    .closest( tbody )
                    .find( tr td:nth-child(2) )
                    .each(
                        function(){
                            if ($(this).text() == id){
                                $(this)
                                    .closest( tr )
                                    .not(thatRow)
                                    .addClass( disabled )
                                    .find( input:checkbox )
                                    .prop( disabled ,true);
                            }
                        });
            }
            else {
                that
                    .closest( tbody )
                    .find( tr td:nth-child(2) )
                    .each(
                        function(){
                            if ($(this).text() == id){
                                $(this)
                                    .closest( tr )
                                    .not(thatRow)
                                    .removeClass( disabled )
                                    .find( input:checkbox )
                                    .prop( disabled ,false);
                            }
                        });
            }
        });​

JS Fiddle demo.

参考资料:

问题回答

如果我正确理解,那么你们都需要在下面这样的检查箱中安装一个点击手器。

rel=“nofollow>>DEMO<>>>

$( #courses > tbody > tr > td > .selectCourse ).on( click , function () {
    var $tr = $(this).closest( tr )
    var selCourseCode = $tr.find( td:eq(1) ).html();
    var isChecked = this.checked;
    if (isChecked) {
        $tr.addClass( highlight );
    } else {
        $tr.removeClass( highlight );
    }

    $.each ($tr.siblings(), function () {
        var courseCode = $(this).find( td:eq(1) ).html();
        if (courseCode == selCourseCode) {
            if (isChecked) {
                $(this).find( .selectCourse ).prop( disabled , true);
                $(this).addClass( disable );
            } else {
                $(this).find( .selectCourse ).removeProp( disabled );
                $(this).removeClass( disable );
            }
        }
    });
});

<>CSS:

.highlight { background-color: #386C98; }
.disable { background-color: #386C98; color: grey; }

这里的“j Query”功能样本应使用旧版本的IEE(8/7/6):

当你生成桌子时,就向html电池加一 at。

 <td data-course-name="math">math</td>

使用jquery审判

 $( td[data-course-name=  + name of the course +  ] ).css( apply css here)

简单





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签