问题
I am adding a click event (display alert on click) to a html hyperlink inside an UpdatePanel on document(ready). However, the event never gets fired when I click the hyperlink. Is it because of ASync postback? What is the correct way to do this?
$(document).ready(function(){
$('#addExcl').click(function(){
alert('asassasaas');return false;
});
});
回答1:
You need to attach the even in every ajax update because the dom struct is change and the events are lost on the part of the update.
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
}
function EndRequest(sender, args) {
$('#addExcl').click(function(){
alert('asassasaas');
return false;
});
}
来源:https://stackoverflow.com/questions/4162641/attach-event-to-hyperlink-click-inside-update-panel