简体   繁体   English

使用jquery访问下拉菜单

[英]Accessing drop down menu using jquery

My HTML code is: 我的HTML代码是:

<div class="nav-collapse collapse">
<ul class="nav nav-pills ddmenu">
    <li class="dropdown "><a href="index.html">Home</a></li>
    <li class="dropdown"><a href="about.html">About</a></li>
    <li class="dropdown active">
        <a href="features.html">Features</a>
        <ul class="dropdown-menu">
            <li><a href="#" id="drp_pbx">Office</a></li>
            <li><a href="#" id="drp_call">Center</a></li>
        </ul>
    </li>
    <li class="dropdown"><a href="apis.html">API</a></li>
    <li class="dropdown"><a href="downloads.html">Download</a></li>
    <li class="dropdown"><a href="blogs.php">Blog</a></li>
    <li class="dropdown"><a href="contact.php">Contact</a></li>
</ul>

I got to drop downs menu under 'features.html' and I wrote JQuery to display drp_pbx and drp_call drop content depend on click event 我得到'features.html'下的下拉菜单,我写了JQuery来显示drp_pbxdrp_call drop content取决于click事件

My JQuery is: 我的JQuery是:

$(document).ready(function () {
    $("#callcenter_features").hide();

    $('#drp_pbx, #drp_call').click(function () {
        if (this.id == 'drp_pbx') {
            $("#pbx_features").show();
        }
        else if (this.id == 'drp_call') {
            $("#pbx_features").hide();
            $("#callcenter_features").show();
        }
    });
});

If I am at features.html table every thing works as expected, if I tried from some other pages to access drp_pbx and drp_call functionalities not working properly, even if I clicked drp_call it always appear content of drp_pbx . 如果我在features.html表中,每个东西都按预期工作,如果我尝试从其他一些页面访问drp_pbxdrp_call功能不能正常工作,即使我点击drp_call它总是出现drp_pbx内容。

I want to display content according to my click event of JQuery. 我想根据我的JQuery点击事件显示内容。

Try hiding the other menu if the second one is clicked: 如果单击第二个菜单,请尝试隐藏其他菜单:

$(document).ready(function () {
  $("#callcenter_features").hide();

  $('#drp_pbx, #drp_call').click(function () {
    if (this.id == 'drp_pbx') {
        $("#callcenter_features").hide();
        $("#pbx_features").show();
    }
    else if (this.id == 'drp_call') {
        $("#pbx_features").hide();
        $("#callcenter_features").show();
    }
  });
});

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

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