当一个元素的innerHTML因为"ajaxing“而改变的时候,我想捕捉这个事件。
我的意思是这样的:
$('.t_error span').html.change(function(){
...
});感谢您的帮助!
发布于 2011-07-21 17:39:46
没有办法做你要求的事情--但是,你可以使用下面的结构:
$.ajax({
type: "GET",
url: yourUrl:,
success: function (data) {
ajaxComplete();
}
}); function ajaxComplete()
{
....
}编辑:如果你想更聪明,你可以使用Custom Events
基本上定义一个CustomEvent函数:
var CustomEvent = function() {
//name of the event
this.eventName = arguments[0];
var mEventName = this.eventName;
//function to call on event fire
var eventAction = null;
//subscribe a function to the event
this.subscribe = function(fn) {
eventAction = fn;
};
//fire the event
this.fire = function(sender, eventArgs) {
this.eventName = eventName2;
if(eventAction != null) {
eventAction(sender, eventArgs);
}
else {
alert('There was no function subscribed to the ' + mEventName + ' event!');
}
};
};然后,您只需要在某个位置创建CustomEvent类的一个实例:
var myEvent = new CustomEvent("my event");在您的页面中,订阅它:
myEvent.subscribe(function(sender, eventArgs) {
alert(eventArgs.message);
});并在Ajax调用成功函数中触发它:
$.ajax({
type: "GET",
url: yourUrl:,
success: function (data) {
myEvent.fire(null, {message: 'you just witnessed the firing of a custom event called ' + this.eventName + '!'});
}
});https://stackoverflow.com/questions/6774043
复制相似问题