GridView 上的 jQuery 函数在页面回发后停止工作(鼠标悬停、单击)

发布于 2024-12-14 23:59:29 字数 1837 浏览 5 评论 0原文

我的所有 jQuery 函数在第一次加载页面时都能完美运行,在我执行回发后,会为 GridView 填充行过滤器,并根据行过滤器再次绑定网格。我的 GridView 完全由代码构建并呈现为表格。在此回发之后,鼠标悬停、鼠标移出和单击表中的行的功能不再起作用。

我将 jQuery 函数放在 document.ready 函数中。我还注意到在回发之前这被添加到行的 html 中:

<tr jQuery1320916="3">

所以基本上是每行末尾的序列 (3) 和一些随机数,前面有 jQuery。回发后,这将从行中删除。

这是我的 jQuery 代码的一部分(第一次单击功能在 PostBack 之后仍然有效,但 GridView 上的功能不再有效):

 $(document).ready(function(){
        //start click function select all
        $('input[id$="SelectDeselectAllBox"]').click(function(){            
        //start if
        if($(this).is(':checked')){
           $(this).parent().parent().parent().parent().children().find('input:checkbox').attr('checked',true).closest('tr').addClass('SelectedRow')
        }else{
            $(this).parent().parent().parent().parent().children().find('input:checkbox').attr('checked',false).closest('tr').removeClass('SelectedRow')};
        //end if

        //end click function select all
             });


        //highligth hovered row
             $('table[id^=taskgrid] tbody tr').mouseover(function () {
                 $(this).addClass('HightlightRow');
             }).mouseout(function () {
                 $(this).removeClass('HightlightRow');
             });            

        //end document ready
        });

我是否遗漏了一些东西,提前致谢。

我确实发现jQuery不再通过这种方法找到我的gridview:

$('table[id^=taskgrid] tbody tr'),如果我填写taskgrid的总ID那么它就可以工作。但这对我来说不是选择。

    //is everthing checked? start if
 if($(this).parent().find('input:checkbox:not(:checked)').length == 0){
    $(this).parent().parent().parent().parent().find('input:checkbox:first').attr('checked',true)
    }else{
    $(this).parent().parent().parent().parent().find('input:checkbox:first').attr('checked',false)};
//end if

All my jQuery functions work perfectly the first time the page is loaded, after I do a postback which causes a rowfilter to be filled in for a GridView and binds the Grid again based on the rowfilter. My GridView is built up totally from code and rendered as a table. After this PostBack the function mouseover, mouseout and click on the table rows in my table do not work anymore.

I place my jQuery functions inside document.ready function. I also noticed before the postback this is added to the html of the rows:

<tr jQuery1320916="3">

So basically a sequence at the end of each row (3) and some random numbers with jQuery in front of it. After the postback this is removed from the rows.

Here is a part of my jQuery code (the first click function still works after PostBack but the functions on the GridView not anymore):

 $(document).ready(function(){
        //start click function select all
        $('input[id$="SelectDeselectAllBox"]').click(function(){            
        //start if
        if($(this).is(':checked')){
           $(this).parent().parent().parent().parent().children().find('input:checkbox').attr('checked',true).closest('tr').addClass('SelectedRow')
        }else{
            $(this).parent().parent().parent().parent().children().find('input:checkbox').attr('checked',false).closest('tr').removeClass('SelectedRow')};
        //end if

        //end click function select all
             });


        //highligth hovered row
             $('table[id^=taskgrid] tbody tr').mouseover(function () {
                 $(this).addClass('HightlightRow');
             }).mouseout(function () {
                 $(this).removeClass('HightlightRow');
             });            

        //end document ready
        });

Am I missing something, thanks in advance.

I did discover that jQuery does not find my gridview anymore by this method:

$('table[id^=taskgrid] tbody tr'), if I fill in the total ID of the taskgrid then it does work. But this is not option for me.

    //is everthing checked? start if
 if($(this).parent().find('input:checkbox:not(:checked)').length == 0){
    $(this).parent().parent().parent().parent().find('input:checkbox:first').attr('checked',true)
    }else{
    $(this).parent().parent().parent().parent().find('input:checkbox:first').attr('checked',false)};
//end if

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗼ふ静 2024-12-21 23:59:29

问题是,您正在使用“开头为”选择器:

$('table[id^=taskgrid] tbody tr')

对于 ASP.NET WebForms 生成的 id,最好使用“结尾为”选择器。假设您的 GridView id 是“taskgrid”,请尝试使用以下选择器:

$('table[id$="taskgrid"] tbody tr')

如果您的目标是多个表元素并且“taskgrid”只是 id 的一部分,则可以使用“contains”选择器:

$('table[id*="taskgrid"] tbody tr')

The problem is, that you are using "starts with" selector:

$('table[id^=taskgrid] tbody tr')

It is better to use "ends with" selector for ASP.NET WebForms generated id. Assuming your GridView id is "taskgrid", try using following selector:

$('table[id$="taskgrid"] tbody tr')

In case you are targeting several table elements and "taskgrid" is only part of id, you can use "contains" selector:

$('table[id*="taskgrid"] tbody tr')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文