[英]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.