gpt4 book ai didi

javascript - 在通用菜单加载完成之前不要继续

转载 作者:行者123 更新时间:2023-11-28 14:22:07 26 4
gpt4 key购买 nike

我有一个通用菜单,我将其包含在我的所有 HTML 中。某些菜单项默认设置为“禁用”,因为它们只能从某些页面访问。当显示允许的页面之一时,我删除禁用的类。有时,禁用的类不会被删除,用户会看到一个带有一条线的红色圆圈。我尝试过“holdReady”和“(window).load”,但它们不起作用。

如果我在删除该类之前发出警报,它就会起作用。

代码是:

//$.holdReady( true );
////Include the menu before the document is ready.
//$("#includedContent").load("Menu.html");
//$.holdReady( false );

$(document).ready(function(){
//Include the menu before the document is ready.
$("#includedContent").load("Menu.html");
});

//$(window).load(function(){

$(document).ready(function(){

//Allow these items to be selected when a youth member is displayed
$("li").removeClass("disabled");

最佳答案

.load() 签名有一个回调函数。在这种情况下,$.holdReady() 是不必要的。您可以将jQuery(selector.context)context设置为调用.load()的元素,即this .load() 回调函数中,仅选择 "li" ,这些元素是具有 id “includedContent”的元素的子元素`

$(function() {
$("#includedContent").load("Menu.html", function() {
// do stuff
$("li", this).removeClass("disabled");
});
});

关于javascript - 在通用菜单加载完成之前不要继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54840086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com