我有两个“ul”列表。使用 javascript a 从第二个列表中删除子项并添加到第一个 ul 列表中。但是当页面加载时,第二个菜单看起来没有样式。见here和 web
这是代码。 #main-menu 和#section menu 是 ul 列表:
//dinamyc main menu
if( $('body').hasClass('page-template-templateshome-page-php') ){
$('#section_menu').children().each(function(i, e){
var firstLi = '#' + $('.navbar').next().attr("id");
$('.home .menu-item-home a').removeClass('external').attr( "href", firstLi );
if($('#main-menu div ul li').is($(e).insertAfter('#main-menu ul li:eq(0)'))){
$(e).insertAfter('#main-menu ul:eq(0)');
}
$('#section_menu').css('display','none');
});
}else{
$('#section_menu ').children().remove();
$('#section_menu').remove();
}
CSS:
#section_menu { display:none; }
最佳答案
<div id="hidden-during-page-load">Loading...</div>
$(window).load(function(){
// this will ensure that all content has loaded before the div is shown
$("#hidden-during-page-load").show();
});
#hidden-during-page-load {
display:none;
}
关于javascript - 在页面加载时隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22234219/