BIND通过Ajax调用jQuery的方法为Html装 [英] Bind jQuery method to Html loaded through an Ajax call
本文介绍了BIND通过Ajax调用jQuery的方法为Html装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从一个AJAX调用加载的内容,但我想绑定一个自定义的方法(而不是一个事件)的DOM元素来实现一些功能。
大多数的解决方案我在网上找到的是结合活动的网页像
$(例如)。AJAX({
成功:功能(数据){
东西()
}
})
我想'上的内容加载实现类似,因为没有事件有..
$('后')。住('LOAD',函数(){
.....
});
解决方案
考虑 .ajaxComplete
。
http://api.jquery.com/ajaxComplete/
例如:
//通常你有一个匿名函数。使它成为一个命名的功能。
功能myInitialize(范围){
$('按钮',范围).button();
}
//文件准备初始化的东西,在页面加载调用它。
$(myInitialize(空));
//在.ajaxComplete再次调用它
//'这'是加载或有新的内容股利。
$('*')ajaxComplete(myInitialize(本));
I have content that is loaded from an ajax call but i want to bind a custom method (not an event) to the dom elements to achieve some functionality.
Most of the solutions i find online are binding events to the page like
$(".example").ajax({
'success': function(data) {
something()
}
})
I want to achieve something like 'on load of the content' because there is no event there..
$('.post').live('load', function() {
.....
});
解决方案
Consider .ajaxComplete
.
http://api.jquery.com/ajaxComplete/
For example:
// 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));
这篇关于BIND通过Ajax调用jQuery的方法为Html装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文