开发者

Why is the dblclick event working like the click event?

开发者 https://www.devze.com 2023-03-27 01:53 出处:网络
$(\'#ajax-links a\').live(\'click\', function(e) { var url = $(this).attr(\'href\'); url = url.replace(/^.*#/, \'\');
$('#ajax-links a').live('click', function(e) {
    var url = $(this).attr('href');
    url = url.replace(/^.*#/, '');
    $.history.load(url);
    return false;
});

Whenever I replace 'click' with 'dblclick' it still behaves as the click event. The demo is here (http://www.serpere.info/jquery-history-plugin/samples/ajax/)开发者_StackOverflow社区 and the source can be download from here : https://github.com/tkyk/jquery-history-plugin/tree/master/samples/


Try prevent default on single click when adding dblclick:

Instead of return false; you can prevent the default action for the event:

If you don't want the event to bubble throw the DOM you can use the event.stopPropagation() function

$('#ajax-links a').live('click', function(event) {
    event.preventDefault();
});
$('#ajax-links a').live('dblclick', function(event) {
    event.preventDefault();
    var url = $(this).attr('href');
    url = url.replace(/^.*#/, '');
    $.history.load(url);
});

Dblclick events only gets fired at dblclick: see: jsfiddle.net/cR5ZS

The reason you think its get fired on single click can be that your link refers to something like: #/some_page/ and your dblclick event handler does almost the same. Saves /some_page/ with $.history plugin and in my experience the $.history plugin does almost the same: takes the url parsed to with the call and puts it in the hash : url=/some_page/ becomes #/some_page/

Andreas

0

精彩评论

暂无评论...
验证码 换一张
取 消