我的所有jQuery函數都在第一次加載頁面時完美工作,之後我執行一個回發,導致爲GridView填充rowfilter並綁定Grid再次基於rowfilter。我的GridView完全由代碼構建,並以表格的形式呈現。在此PostBack之後,函數mouseover,mouseout並單擊我表中的錶行不再工作。GridView上的jQuery函數在頁面回傳後停止工作(鼠標懸停,單擊)
我把我的jQuery函數放在document.ready函數中。我回發,這是添加到行的HTML之前還注意到:
<tr jQuery1320916="3">
所以基本上在每行(3),並在它的前面用jQuery一些隨機數結束的序列。回發之後,這將從行中刪除。
這裏是我的jQuery代碼的一部分(第一個點擊功能還是回傳後的作品,但在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了:
$( '表[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
檢查此問題:http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels –
我沒有在我的解決方案中使用UpdatePanel,引用該問題的答案:「PageRequestManager是一個JavaScript對象,如果更新面板位於頁面上,則該對象自動可用。「 – user1039394