简体   繁体   English

Bootstrap Twitter Dropdown:让父母点击链接

[英]Bootstrap Twitter Dropdown: Make the parent follow the link

I have this bootstrap twitter dropdown menu. 我有这个bootstrap twitter下拉菜单。 I replaced the click event with hover event. 我用click事件替换了click事件。 Now the only problem is is supposed to follow www.google.com but it doesn't. 现在唯一的问题是应该关注www.google.com,但事实并非如此。 I tried with: 我尝试过:

 jQuery(".nav .dropdown-toggle").click(function () {
      return true;
    });

but no dice. 但没有骰子。

Here is the code: 这是代码:

<html>
  <head>
    <title>text</title>
    <link type="text/css" rel="stylesheet"  href="docs/assets/css/bootstrap.css"/>
    <link type="text/css" rel="stylesheet"  href="docs/assets/css/bootstrap-responsive.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-dropdown.js"></script>
    <script type="text/javascript">
      $(function(){
        jQuery('.dropdown-toggle').dropdown();
        jQuery('ul.nav li.dropdown').hover(
        function() {jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn();},
        function() {jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut();}
      );

        jQuery(".nav .dropdown-toggle").click(function () {
          return true;
        });
      });
    </script>

  </head>
  <body>
    <ul class="nav nav-pills">
      <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="http://www.google.com">
          Dropdown
          <b class="caret"></b>
        </a>
        <ul class="dropdown-menu">
          <li><a href="#">text</a></li>
          <li><a href="#">text</a></li>
        </ul>
      </li>
    </ul>

  </body>
</html>

http://jsfiddle.net/rgdwM/ http://jsfiddle.net/rgdwM/

You can accomplish this with no JavaScript by changing the markup a bit and adding a CSS class. 您可以通过稍微更改标记并添加CSS类来完成此操作。

Change the HTML markup to (**note disabled is added next to dropdown-toggle):** 将HTML标记更改为(**注释 禁用在下拉切换旁边添加):**

<a class="dropdown-toggle disabled" data-toggle="dropdown" data-target="#" href="http://www.google.com">
    Dropdown
    <b class="caret"></b>
</a>

If you want the submenu to appear on hover (since clicking will now go to the specified url), add this CSS class: 如果您希望子菜单显示在悬停上(因为现在单击将转到指定的URL),请添加此CSS类:

.nav li.dropdown:hover .dropdown-menu
{
    display: block;    
}

This applies to Bootstrap version 2.3.1. 这适用于Bootstrap版本2.3.1。

Not really too sure on what you are trying to achieve here. 你真正想要实现的目标并不是很确定。

But this would make the .click() take you to google. 但这会使.click()带你去谷歌。

$(".nav .dropdown-toggle").click(function () {
  window.location = "http://www.google.com";
});

As for why the <a> click event is eaten I am not currently sure. 至于为什么<a>点击事件被吃掉,我目前不确定。

If you want the parent to follow the link on Wordpress use this: 如果您希望父母关注Wordpress上的链接,请使用以下命令:

    $(".nav .dropdown-toggle").click(function () {
    window.location = $(this).attr('href');
    });

Bootstrap 3.0 docs say to use the data-target attribute to preserve clickable links. Bootstrap 3.0文档说使用data-target属性来保留可点击链接。

So, your HTML would become: 那么,你的HTML将成为:

<a class="dropdown-toggle" data-toggle="dropdown" data-target="http://www.google.com" href="#">
    Dropdown
    <b class="caret"></b>
</a>

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

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