简体   繁体   English

Bootstrap导航折叠链接在移动设备上不起作用

[英]Bootstrap nav-collapse links not working on mobile

I'm having a problem regarding dropdown menus not working on mobile devices that i've been struggling with for a week. 我在下拉菜单无法正常工作一个星期的移动设备上遇到问题。 I've taken a copy of the current example from the bootstrap site, modified it a bit and during the test i noticed it didn't work as expected. 我从引导站点上获取了当前示例的副本,对其进行了一些修改,并且在测试期间我发现它没有按预期工作。 (same goes for the original example( http://twitter.github.io/bootstrap/examples/carousel.html ), where i only add a link to for instance google) - why this behaviour? (原始示例也是如此( http://twitter.github.io/bootstrap/examples/carousel.html ),在该示例中,我仅添加了指向google的链接)-为什么这种行为?

<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="brand" href="#">Dropdown test</a>
      <div class="nav-collapse collapse">
        <ul class="nav">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-target="#">Links<span class="caret"></span></a>       
            <ul class="dropdown-menu">
              <li><a href="http://www.google.com" target="blank">Google (opens in new window)</a></li>
              <li><a href="http://www.bing.com" target="blank">Bing (opens in new window)</a></li>
              <li><a class="linkcheck" href="http://www.google.com">Google</a></li>
              <li><a class="linkcheck" href="http://www.bing.com">Bing</a></li>
            </ul>
          </li><!-- .dropdown -->
        </ul><!-- .nav -->
      </div><!-- .nav-collapse -->
    </div><!-- .container -->
  </div><!-- .navbar-inner -->
</div><!-- .navbar -->

Bootstrap is new to me, and i can't find any documentation on nav-collapse, where can i find this? Bootstrap对我来说是新手,而我在nav-collapse上找不到任何文档,在哪里可以找到? And do i really have to do a click event, then window.open(url)? 我真的必须要做一个点击事件,然后是window.open(url)吗? (or does onclick behave different on a mobile device?) (或者onclick在移动设备上的行为是否有所不同?)

Here's my online example: http://test-web.dk/sandbox/bootstrap/ 这是我的在线示例: http : //test-web.dk/sandbox/bootstrap/

Edit: Found a solution: 编辑:找到一个解决方案:

$('.linkcheck', this).click(function(){
  var url = $(this).attr('href');
  alert("link clicked:" + url);
  if(url.match(/^http:/)) {
    window.location.href = url;
  }
});

// fix by RobDodson: github.com/twitter/bootstrap/issues/4550
// Kills regular links in browsers though, but they will be redirected by linkcheck above
$('.dropdown a').click(function(e) {
  e.preventDefault();
  setTimeout($.proxy(function() {
    if ('ontouchstart' in document.documentElement) {
      $(this).siblings('.dropdown-backdrop').off().remove();
    }
  }, this), 0);
});

Still, a real bootstrap solution would be nice to known, rather than a hack :-) So if anybody has a suggestion, please post it. 不过,真正的引导程序解决方案将是广为人知的,而不是黑客:-)所以,如果有人有建议,请发布。

Check that you are using the most up to date jQuery. 检查您使用的是最新的jQuery。

I was having the same problem with the Bootstrap theme for Drupal, but solved this problem by changing the settings in jQuery Update to the most up to date! 我在Drupal的Bootstrap主题上遇到了同样的问题,但是通过将jQuery Update中的设置更改为最新来解决了这个问题!

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

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