简体   繁体   English

无法启用或禁用jQuery菜单栏项

[英]Can't enable or disable jquery menubar items

I'm using a jquery ui menubar. 我正在使用一个jQuery UI菜单栏。 So far I had good results, but I'm trying to programmatically enable and disable menubar items(eg file->exit). 到目前为止,我取得了不错的结果,但是我正在尝试以编程方式启用和禁用菜单栏项(例如,file-> exit)。 This just doesn't work for me. 这对我不起作用。

Part of the html definition of the menubar is: 菜单栏的html定义的一部分是:

 <div class="Dashboard">
  <ul id="MainMenubar" class="menubar-icons">
    <li>
      <a href="#File">File</a>
      <ul>
        <li class="ui-state-disabled" id="logout"><a href="#Logout">Logout</a></li>
        <li class="ui-state-disabled"><a href="#LoadUsers">Load users</a></li>
        <li><a href="#Exit">Exit</a></li>
      </ul>
    </li>
  </ul>
</div>

Now when I call: $( "#logout" ).menubar( "enable" ); 现在,当我调用时: $( "#logout" ).menubar( "enable" ); , I get the following error: "Uncaught Error: cannot call methods on menubar prior to initialization; attempted to call method 'enable'". ,出现以下错误:“未捕获的错误:初始化之前无法在菜单栏上调用方法;​​尝试调用方法'enable'”。 I don't understand, because the menubar is initialize long before, when the page is loaded. 我不明白,因为菜单栏是在加载页面之前很早就初始化的。

What am I doing wrong? 我究竟做错了什么? Thank you 谢谢

#Logout is an HREF for a URL in your code, not an ID. #Logout是代码中URL的HREF,而不是ID。 You need to assign the HTML attribute id="Logout" to some element in order to reference it the way you are doing here. 您需要将HTML属性id="Logout"分配给某个元素,以便以此方式对其进行引用。

For example: 例如:

<li id="logout"><a href="#">Logout</a></li>

$("#logout").menubar("enable"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM