最新版本的twitter bootstrap(2.3.2)似乎确实存在移动设备下拉菜单的问题。
打开菜单后单击下拉菜单项时,菜单只会关闭,并且不会点击任何链接。 您可以在此处的示例页面上看到此内容:http://twitter.github.io/bootstrap/examples/hero.html
我发现在他们的github页面上发布了一个问题但没有解决方案:https://github.com/twitter/bootstrap/issues/7927
有人知道解决它的诀窍吗?
答案 0 :(得分:36)
临时修复是添加
.dropdown-backdrop{
position: static;
}
到css文件。
答案 1 :(得分:8)
这对我有用:
$('.dropdown-toggle').click(function(e) {
e.preventDefault();
setTimeout($.proxy(function() {
if ('ontouchstart' in document.documentElement) {
$(this).siblings('.dropdown-backdrop').off().remove();
}
}, this), 0);
});
通过github上的robdodson
答案 2 :(得分:2)
对我来说,它有助于增加我的风格:
.dropdown-backdrop {
z-index:0;
}
与马蒂亚斯几乎相同的答案,我希望它有所帮助。
答案 3 :(得分:0)
我已经解决了这个问题。
我的代码在这里
<li class="dropdown custom open"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> menu<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Sub menu</a></li>
<li><a href="#">Sub menu2</a></li>
</ul>
</li>
在CSS fie中添加以下样式。
@media (max-width: 767px) {
.dropdown.custom:hover .dropdown-menu {
visibility: visible;
display:block;
border-radius:0;
}
}
答案 4 :(得分:0)
通常的答案似乎都没有解决我们在Android上遇到的问题。我们在这里尝试了接受的答案以及一些javascript黑客攻击: Bootstrap Collapsed Menu Links Not Working on Mobile Devices 和 http://alittlecode.com/fix-twitter-bootstraps-dropdown-menus-in-touch-screens/
最终我们发现关闭发生的地方,并且只有在父母或祖父母没有clearMenus()
类
dropdown-submenu
$(document)
.on('click.dropdown.data-api', function (e) {
//fix start
var $parent = $(e.target).parent()
var $grandparent = $parent.parent()
if (!$parent.hasClass('dropdown-submenu') && !$grandparent.hasClass('dropdown-submenu')) {
clearMenus()
}
//clearMenus
//end fix
})
.on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
.on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
}(window.jQuery);
希望有所帮助!
答案 5 :(得分:0)
尝试一下。对我来说有用
@media only screen and (max-width: 768px) {
.dropdown-menu {
position: absolute;
}
}
答案 6 :(得分:-1)
$('.dropdown a').click(function(e) {
e.preventDefault();
setTimeout($.proxy(function() {
if ('ontouchstart' in document.documentElement) {
$(this).siblings('.dropdown-backdrop ').off().remove();
}
}, this), 0);
});