2014-02-26 134 views
0

我有一個帶有UpdatePanel的asp.net頁面,並且希望通過Ajax調用使滾動事件hander持久。我得到它爲輸入元素更改事件(見最後一個例子)工作,但我很難與div元素的sroll事件。JQuery On()不適用於div

$(document).ready(function() 
{ 

/* working event fires but not after ajax call */ 
$("#ctl00_cirsContent_divReportLeft").on("scroll", function() { 
    alert("test scroll left"); 
}); 

/* this one does not work at all */ 
$(document).on("scroll", "#ctl00_cirsContent_divReportRight", function() { 
    alert("Test scroll"); 

}); 

/* this one works both before and after ajax call */ 
$(document).on("change", "#ctl00_cirsContent_CtlCalendar1_txtDate", function() { 
    alert("Test type"); 

}); 

}); 

我錯過了什麼?

感謝

+1

請注意:*只是想法* - >如果您使用的是C#用戶控件,並且此輸入的'id' =>'ctl00_cirsContent_divReportLeft'是動態生成的,我建議您使用'class'屬性。這應該工作。好的細節在這裏:https://api.jquery.com/on/ –

回答

0

嘗試使用$(window)而不是$(document)

$(window).on("scroll", "#ctl00_cirsContent_divReportRight", function() { 
    alert("Test scroll"); 
}); 
+0

謝謝,但沒有任何區別,也不起作用。 – borntosucceed

+0

你可以嘗試使用class而不是'id'就像Tats_innit建議 – Felix

0

結束了使用頁面加載事件,而不是$(文件),這一解決方案。就緒:

function pageLoad(sender, args) 
{ 
    if (args.get_isPartialLoad()) 
    { 
    registerScrollEvent(); 
    } 
} 

和這在registerScrollEvent

$("div[id$='divReportLeft']").scroll(function() { 
.... some code 
    });