[英]jQuery functions on GridView stop working after PostBack on page (mouseover, click)
在执行回发后,我的所有jQuery函数在首次加载页面时均能完美运行,这将导致为GridView填充行过滤器,并再次基于行过滤器绑定网格。 我的GridView完全由代码构建并呈现为表格。 在此“回发”之后,将函数悬停在鼠标上,将鼠标移出并单击我的表中的表行不再起作用。
我将jQuery函数放在document.ready函数中。 在回发之前,我还注意到这被添加到行的html中:
<tr jQuery1320916="3">
因此基本上是每行(3)末尾的序列,前面是jQuery的一些随机数。 回发后,将其从行中删除。
这是我的jQuery代码的一部分(FirstClick函数在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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.