简体   繁体   English

Bootstrap下拉菜单无法正常运行

[英]Bootstrap dropdown menu is not functioning properly

I'm working on a small project using Bootstrap, and I've come across a weird problem. 我正在使用Bootstrap进行一个小项目,但遇到了一个奇怪的问题。

Basically, I have this menu with two items, where the first loads another page inside a div, and the second triggers a dropdown menu. 基本上,我有两个菜单项,其中第一项在div中加载另一个页面,第二项触发一个下拉菜单。

The problem is that if I click on the first item right after I run the file on browser, the dropdown will stop working until I click the first item again. 问题是,如果我在浏览器上运行文件后立即单击第一项,则该下拉列表将停止工作,直到再次单击第一项。

If I click the second item first, the dropdown will also stop working until I click the first item. 如果我先单击第二项,则下拉菜单也将停止工作,直到我单击第一项。

Here's the code: 这是代码:

 $('#usuarios').click(function() { $('#main').load('cns_usuarios.html'); }); $('#canal').click(function() { $('#main').load('canal.html'); }); $('#campos').click(function() { $('#main').load('cns_campos.html'); }); 
 <link href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css' rel='stylesheet'> <link href='index.css' rel='stylesheet'> <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> <script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js'></script> <ul class='breadcrumb menu'> <li id='usuarios'><a href='#'>Listar Usuários</a> </li> <li class='dropdown'> <a class='dropdown-toggle' data-toggle='dropdown' href='#'> Configurações <span class = 'caret'></span> </a> <ul class='dropdown-menu'> <li id='canal'><a href='#'>Canal</a> </li> <li id='campos'><a href='#'>Campos</a> </li> </ul> </li> <li><a href='../index.html'>Sair</a> </li> </ul> <div id='main' class='main'> </div> 

The code contains some stuff in portuguese, but it's pretty much irrelevant so just ignore it. 该代码包含葡萄牙语中的某些内容,但是它几乎无关紧要,因此请忽略它。

Also, I've added a few things of my own, but only on the css side. 另外,我添加了一些自己的东西,但仅在CSS方面。 If anyone thinks it might be causing my problem I'll show that part of the code too. 如果有人认为这可能会导致我的问题,我也会在代码中显示该部分。

Try this: 尝试这个:

<script>
    $(document).on('click', '#usuarios', function() {
        $('#main').load('cns_usuarios.html');
    });

    $(document).on('click', '#canal', function() {
        $('#main').load('canal.html');
    });

    $(document).on('click', '#campos', function() {
        $('#main').load('cns_campos.html');
    });

</script>

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

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