1

我遇到有關下拉菜單無法在移動設備上工作的問題,我一直在努力工作一週。我從bootstrap網站獲取了當前示例的一個副本,對其進行了一些修改,在測試期間我發現它並未按預期工作。 (原來的例子也是如此(http://twitter.github.io/bootstrap/examples/carousel.html),我只添加了一個鏈接,例如谷歌) - 爲什麼這種行爲?自舉導航崩潰鏈接無法在移動設備上工作

<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 --> 

引導是新的給我,我找不到導航崩潰的任何文件,我在哪裏可以找到呢? 我真的必須做點擊事件,然後window.open(url)? (或根本的onclick行爲在移動設備上的不同?)

這是我在網上例如:http://test-web.dk/sandbox/bootstrap/

編輯: 找到了解決辦法:

$('.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); 
}); 

不過,真正的自舉解決方案將是不錯的知道,而不是一個黑客:-)所以,如果有人有一個建議,請張貼它。

+0

另一個簡單的修復:https://github.com/Bitergia/bootstrap/commit/25e8eeb –

回答

2

檢查您使用的是最新的jQuery。

我與Drupal的Bootstrap主題有同樣的問題,但通過將jQuery Update中的設置更改爲最新版本來解決此問題!

相關問題