2014-02-26 133 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 
    });