Jquery在A Href上创建双击事件

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

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

如果你想“拦截”click事件,以便双击事件有可能在页面重定向之前触发,那么你可能需要在点击上设置超时,如下所示:

$('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/

如果您a链接ID为“id”,则:

 $("#id").bind("dblclick", ....);