Jquery在A Href上创建双击事件 [英] Jquery create Double Click event on A Href

查看:78
本文介绍了Jquery在A Href上创建双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计可以使用jquery为a href创建双击事件

Guys is it possible to create double click event for the a href using jquery

推荐答案

执行操作的问题双击锚点是页面将在第一次点击时重定向,防止双击及时响应。

The problem with performing an action on double click of an anchor is that the page will redirect on the first click, preventing the double click from responding in time.

如果你想拦截点击事件这样双击事件有可能在页面重定向之前触发,然后你可能需要在点击上设置超时,如下所示:

If you want to "intercept" the click event so that the double click event has a chance to fire before the page redirects, then you may have to set a timeout on the click like this:

$('a').click(function () {
    var href = $(this).attr('href');

    // Redirect only after 500 milliseconds
    if (!$(this).data('timer')) {
       $(this).data('timer', setTimeout(function () {
          window.location = href;
       }, 500));
    }
    return false; // Prevent default action (redirecting)
});

$('a').dblclick(function () {
    clearTimeout($(this).data('timer'));
    $(this).data('timer', null);

    // Do something else on double click

    return false;
});

演示: http://jsfiddle.net/4788T/1/

这篇关于Jquery在A Href上创建双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆