我使用的是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');
});发布于 2012-05-18 03:04:34
因为您的代码在body的子元素中,所以一旦您用另一个div包装了body的内容,body中的脚本就会被重新执行。只需在使用wrapInner之前删除这些脚本即可。移除脚本不会影响页面的功能,只是不会导致警报发生两次。
$("body").find("script").remove().end().wrapInner("<div id='root' />");https://stackoverflow.com/questions/10640620
复制相似问题