jQuery高亮显示带有复选框的行,请单击 [英] JQuery highlight row with checkbox click

查看:65
本文介绍了jQuery高亮显示带有复选框的行,请单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(document).ready(function(){
    $(".txtDate").datepicker({ showOn: "both", 
        buttonImage: "library/ui/datepicker/img/calendar2.gif", dateFormat: "yy/mm/dd", buttonImageOnly: true });

    //added this checkbox click for something I given earlier

    $("#Table input").click(function() { 
        if ($(this).attr("checked") == true)
        {
            $(this).parent().parent().addClass("highlight");  
        } 
        else
        {   
            $(this).parent().parent().removeClass("highlight");
        }
    });
});

我在后面的代码中动态添加的每一行都有一个复选框控件

I have a checkbox control for each row that I add dynamically in code behind

for( int i=0; i< data.count;i++){   
    HtmlTableCell CheckCell = new HtmlTableCell();
    CheckBox Check = new CheckBox(); 

    CheckCell.Controls.Add(Check);

    row.Cells.Add(CheckCell);
    Table.Rows.Add(row);
}

带有标记的表ID在这里:

table id with markup is here:

<table id="Table"  runat="server" width="100%" cellspacing="5" border="1"> 
    <colgroup width="3%"></colgroup>
    <colgroup width="15%"></colgroup>
    <colgroup width="20%"></colgroup>
    <colgroup width="15%"></colgroup>
    <colgroup width="47%"></colgroup>
    <thead>
        <tr> 
            <th id="CheckBox" runat="server"><input type="checkbox" id="CheckBox1" name="CheckBox" runat="server" /></th>
            <th id="Type" runat="server"></th>
            <th id="Category" runat="server"></th>  
            <th id="DateTime" runat="server"></th>  
            <th id="Description" runat="server"></th>
        </tr>
    </thead> 
    <tbody>
    </tbody>
</table>

推荐答案

是的-我的回答也被修改了.

Yea - my answer just got zapped too.

无论如何,如果您使用的是asp.net,则名称会混乱(类似于ctl100_Table之类的东西),您需要将其放入jquery中而不是Table中.

Anyway, if you are using asp.net then the names get mangled ( to something like ctl100_Table ) and you need to put this into the jquery instead of Table.

在浏览器中查看实际呈现的html,以获取您需要使用的名称.

Look at the actual rendered html in the browser to get the name you need to use.

您可以尝试使用$("[id $ = Table]).attr(" id)来获取错误的版本.

You can try using $("[id$=Table]).attr("id") to get the mangled version.

这篇关于jQuery高亮显示带有复选框的行,请单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆