[英]JQuery wrapInner triggers jQuery(document).ready twice
我正在使用wrapInner
函数,但是这些函数再次触发了我的jQuery(document).ready
事件。
这是正常行为吗? 如何避免这种情况?
更新:
miscellaneous : function(){
$('#nav .active a').bind('click',function(){ return false });
$('.type-a, .type-b, .type-c, .type-d, .type-e').append('<div class="type"></div>');
//$('body').wrapInner('<div id="root"></div>');
$('#content').wrap('<div id="content-wrapper"></div>');
$('#filter .time > li').append('<span class="arrow"></span>');
$('#filter .category li a').wrapInner('<span></span>');
$('#filter .time > li > ul').hide();
$('#filter .time > li').live('mouseenter',function(){
if($(this).children('ul').css('display') != 'block'){
$(this).children('ul').fadeIn('fast',function(){
$(this).css({'display':'block'});
});
}
}).live('mouseleave',function(){
if($(this).children('ul').css('display') != 'none'){
$(this).children('ul').fadeOut('fast',function(){
$(this).css({'display':'none'});
});
}
});
}
如果我取消注释第四行,则以下警报将显示两次。 带有注释行的警报仅显示一次。
jQuery(document).ready(function($) {
alert('in ready');
});
由于您的代码位于主体的子元素中,因此,将主体的内容包装到另一个div之后,主体中的脚本将被重新执行。 在使用wrapInner之前,只需删除这些脚本。 删除脚本将不会影响您页面的功能,除了不会导致警报发生两次。
$("body").find("script").remove().end().wrapInner("<div id='root' />");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.