gpt4 book ai didi

c# - 页面上的 PostBack 后 GridView 上的 jQuery 函数停止工作(鼠标悬停,单击)

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:11 24 4
gpt4 key购买 nike

我所有的 jQuery 函数在第一次加载页面时都能完美运行,在我执行回发后,这会导致为 GridView 填充 rowfilter 并根据 rowfilter 再次绑定(bind) Grid。我的 GridView 完全由代码构建并呈现为表格。在此 PostBack 之后,函数 mouseover、mouseout 和单击我表格中的表格行不再起作用。

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

<tr jQuery1320916="3">

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

这是我的 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

最佳答案

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

$('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')

关于c# - 页面上的 PostBack 后 GridView 上的 jQuery 函数停止工作(鼠标悬停,单击),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8077439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com