我的代碼...返回false;當鼠標保持(點擊)在x秒
var timer;
var func = function() {
$("body").append("1");
};
$(document).on('mousedown' , 'a' , function(e){
timer = setTimeout(func, 1000);
}).on('mouseup mouseleave' , 'a' , function(e){
clearTimeout(timer);
});
一切工作。但是,當我這個功能設置爲某個鏈接像<a href="http://google.com">text</a>
我需要設置return false;
(不重定向到URL或其他onclick()
功能)
哪裏return false;
我可以在設置?還是另一種解決方案
PS:我要我的鏈接將正常工作時,點擊正常點擊
遊樂場:http://jsbin.com/iwilop/1/edit
How can I listen for a click-and-hold in jQuery?
例如在我的'func'函數? – l2aelba 2013-02-27 10:44:51
不會在'mousup'中返回false嗎? – Christoph 2013-02-27 10:45:15
@ l2aelba:不,你正試圖阻止點擊,對吧?所以在鏈接上阻止它。 – 2013-02-27 10:45:35