gpt4 book ai didi

javascript - 调用 ondblclick 而不调用 onclick-event

转载 作者:技术小花猫 更新时间:2023-10-29 12:25:58 25 4
gpt4 key购买 nike

是否有一个不使用 jquery 的简单解决方案,在 HTML 标签内调用 ondblclick 而不会导致 onclick 发生?

这总是关闭窗口,尽管它应该只显示警报:

<a href="#" ondblclick="alert('dbl')" onclick="window.close();">X</a>

(它仅适用于 javascript 弹出窗口,因为您无法使用 window.close(); 关闭主窗口)

最佳答案

我的猜测是,每个解决方案都会遇到双击超时长度因用户偏好而异的问题,如上面评论中的 Irvin Dominin aka Edward 所述:

From jQuery docs but related: "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 before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable."

我放弃了使用 doubleclick 并使用 CTRL+click 代替:

<a href="#" onclick="if(event.ctrlKey) { 
alert('CTRL+Mouseclick'); return false;
} else { window.close(); }">X</a>

见:

Catch onclick-event with CTRL pressed

关于javascript - 调用 ondblclick 而不调用 onclick-event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18699677/

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