gpt4 book ai didi

javascript - 'click'/'dblclick' 上同一类的不同功能

转载 作者:行者123 更新时间:2023-11-30 08:16:46 25 4
gpt4 key购买 nike

这是我的两个函数,单击它就可以正常工作,但是在 dblclick 上两个函数都执行,知道吗?我尝试使用 live 而不是 delegate 但两个函数仍然在 dblclick 上执行

// Change Status on click
$(".todoBox").delegate("li", "click", function() {
var id = $(this).attr("id");
$.ajax({
//ajax stuff
});

return false;
});



// Double Click to Delete
$(".todoBox").delegate("li", "dblclick", function(){
var id = $(this).attr("id");
$.ajax({
//ajax stuff
});

return false;
});

最佳答案

来自 API 文档:

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events and others only one. If an interface that reacts differently to single- and double-clicks cannot be avoided, then the dblclick event should be simulated within the click handler. We can achieve this by saving a timestamp in the handler, and then comparing the current time to the saved timestamp on subsequent clicks. If the difference is small enough, we can treat the click as a double-click.

我认为这意味着您将在超时处理程序中执行您的click 操作。如果您再次点击,并且超时处理程序尚未发生,您将取消超时并执行 dblclick 代码。

关于javascript - 'click'/'dblclick' 上同一类的不同功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2532966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com