我有从 ajax 调用加载的内容,但我想将自定义方法(而不是事件)绑定(bind)到 dom 元素以实现某些功能。
我在网上找到的大多数解决方案都是将事件绑定(bind)到页面,例如
$(".example").ajax({
'success': function(data) {
something()
}
})
我想实现“加载内容”之类的目标,因为那里没有事件..
$('.post').live('load', function() {
.....
});
最佳答案
考虑.ajaxComplete
。
http://api.jquery.com/ajaxComplete/
例如:
// Normally you have an anonymous function. Make it a named function.
function myInitialize(scope) {
$('.button', scope).button();
}
// Call it in document ready to initialize stuff that loaded in the page.
$(myInitialize(null));
// Call it again in .ajaxComplete
// 'this' is the div that loaded or has new content.
$('*').ajaxComplete(myInitialize(this));
关于jquery - 将 jQuery 方法绑定(bind)到通过 Ajax 调用加载的 Html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4797199/