【问题标题】:Disable link on first click and act as a:hover在第一次单击时禁用链接并充当:悬停
【发布时间】:2016-01-16 18:13:53
【问题描述】:

当用户通过平板设备访问网站时,我想禁用包含下拉菜单的链接,因此,当用户从平板电脑点击链接时:

-> 出现下拉菜单但链接被禁用,然后在第二次点击时链接有效。

我认为这可能已经解决了,但我还没有找到合适的,我正在使用来自here的代码

jQuery(document).ready(function ($) {

    $("li.taphover > a").on('touchstart', function (e) {
        'use strict'; //satisfy the code inspectors
        var link = $(this); //preselect the link
        if (link.hasClass('hover')) {
            return true;
        } else {
            link.addClass('hover');
            $('li.taphover > a').not(this).removeClass('hover');
            e.preventDefault();
            return false; //extra, and to make sure the function has consistent return points
        }
    });

});

但它会禁用链接,并且没有任何效果。

【问题讨论】:

  • $('li.taphover > a').not$(this).removeClass('hover');
  • 把(这个)改成$(这个)
  • 它不起作用,现在第一次点击链接到该站点。

标签: javascript jquery drop-down-menu tablet


【解决方案1】:

我找到了一个简单的 Jquery 插件 here 可以工作。该链接还包含有关如何创建响应式菜单的教程,该菜单会在第一次点击时禁用顶部下拉链接 (li:has(ul))。

【讨论】:

    猜你喜欢
    • 2012-08-20
    • 2015-06-03
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多