Javascript 在$.load(更改了DOM)后初始化插件
我有这样的东西Javascript 在$.load(更改了DOM)后初始化插件,javascript,jquery,events,bind,live,Javascript,Jquery,Events,Bind,Live,我有这样的东西 $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_square' }); 然后我使用$('.menu')。单击(function(){$('#content')。加载(page);}) 如何在页面加载后初始化插件,使其与已加载的新html一起工作 谢谢jquery document.ready在DOM完全加载时执行 范例 $(function(){ //Whatever code you want to
$("a[rel^='prettyPhoto']").prettyPhoto({
theme: 'light_square'
});
然后我使用$('.menu')。单击(function(){$('#content')。加载(page);})
如何在页面加载后初始化插件,使其与已加载的新html一起工作
谢谢jquery document.ready在DOM完全加载时执行 范例
$(function(){
//Whatever code you want to execute after the page is loaded
})
如果希望将函数附加到使用ajax加载到DOM的元素上,可以根据jquery版本使用live或on
如果您使用的jquery版本低于1.7,请使用live
$('.menu').live("click",function(){
//Do whatever you want
});
如果使用jquery 1.7或+,请使用,on
$('body').on("click",".menu",function(){
//do whatever you want
});
将回调作为加载页面时激发的第二个参数:
$('.menu').click(function() {
$('#content').load(page, function() {
$("a[rel^='prettyPhoto']").prettyPhoto({
theme: 'light_square'
});
});
});