简体   繁体   English

Bootstrap子菜单链接不起作用

[英]Bootstrap Submenu links not working

I have seen this question all over the place and I have implemented multiple different solutions I have found but nothing seems to be working. 我已经看到了这个问题,我已经实现了多种不同的解决方案,但我似乎没有任何工作。 I have a bootstrap collapsable menu in which contains submenus. 我有一个bootstrap可折叠菜单,其中包含子菜单。 When a submenu link is clicked, it simply closes the submenu and does not redirect to the link. 单击子菜单链接时,它只关闭子菜单,不会重定向到链接。 I have implemented the following script which I had thought would do the trick: 我已经实现了以下脚本,我曾想过会这样做:

$('.dropdown-toggle').click(function(e) {
    e.preventDefault();
    setTimeout($.proxy(function() {
        if ('ontouchstart' in document.documentElement) {
            $(this).siblings('.dropdown-backdrop').off().remove();
        }
    }, this), 0);
});

This script allows the submenus to dropdown on touchscreen devices, but the links aren't working. 此脚本允许子菜单在触摸屏设备上下拉,但链接不起作用。 I tried removing the e.preventDefault(); 我尝试删除e.preventDefault(); line, but that didn't seem to work either. 但这似乎也不起作用。

How can I get my submenu links to work on mobile touchscreens? 如何让我的子菜单链接在移动触摸屏上工作? They work fine on the desktop and when I hold down on the link on touchscreens I am able to open the correct link up in a new tab, but it doesn't work when you just tap it. 它们可以在桌面上正常工作,当我按住触摸屏上的链接时,我可以在新选项卡中打开正确的链接,但是当您点击它时它不起作用。

EDIT: Here is my a piece of the HTML: 编辑:这是我的一块HTML:

<div class="span3">
    <li class="dropdown-submenu">
        <a href="#" tabindex='-1' class="dropdown-toggle nav-header" data-toggle="dropdown"><i class='icon-time'></i>Time Clock Management</a>
        <ul class='dropdown-menu'>
            <li><a href="#">Labor Scheduling</a></li>
            <li><a href="/change-manager/">Change Manager</a></li>
        </ul>
    </li>
</div>

I fixed this issue by adding the following javascript: 我通过添加以下javascript修复了此问题:

$('.dropdown-submenu ul.dropdown-menu li a').on('touchstart', function(e) {
    e.preventDefault();
    window.location.href = $(this).attr('href');
})

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

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