简体   繁体   English

首次点击时禁用链接,并充当a:h​​over

[英]Disable link on first click and act as a:hover

I want to disable a link which contains a dropdown menu when user access the website via tablet devices, so, when users taps the link from the tablet: 当用户通过平板电脑设备访问网站时,我想禁用包含下拉菜单的链接,因此,当用户点击平板电脑上的链接时:

-> The dropdown appears but the link is disabled, then on the second tap the link works. ->出现下拉菜单,但链接被禁用,然后在第二次点击时,链接起作用。

I think that this is probably solved but I haven't found nothing suitable yet, I'm working with this code from 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
        }
    });

});

But it disables the link, and nothing works. 但是它禁用了链接,并且没有任何效果。

I found a simple Jquery plugin here that works. 我在这里找到了一个有效的简单Jquery插件。 The link also has a tutorial about how to create a responsive menu which disables the top dropdown links (li:has(ul)) on first click. 该链接还提供了有关如何创建响应式菜单的教程,该菜单会在第一次单击时禁用顶部的下拉链接(li:has(ul))。

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

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