D3: How do I set quot;clickquot; event and quot;dbclickquot; event at the same time?(D3:如何设置“点击?事件和“dbclick同时举办活动?)
问题描述
我已经将点击事件切换到一个节点,我也想将一个 dbclick 事件切换到它.但是它只会在我点击它时触发点击事件.
I've toggled click event to a node and I want to toggle a dbclick event to it as well. However it only triggers the click event when I dbclick on it.
那么如何同时设置两个事件呢?
So How do I set both events at the same time?
推荐答案
你必须自己做双击检测
类似的东西可以工作:
var clickedOnce = false;
var timer;
$("#test").bind("click", function(){
if (clickedOnce) {
run_on_double_click();
} else {
timer = setTimeout(function() {
run_on_simple_click(parameter);
}, 150);
clickedOnce = true;
}
});
function run_on_simple_click(parameter) {
alert(parameter);
alert("simpleclick");
clickedOnce = false;
}
function run_on_double_click() {
clickedOnce = false;
clearTimeout(timer);
alert("doubleclick");
}
这是一个有效的 JSFiddle
有关您应该为计时器使用什么延迟的更多信息,请查看此处:如何在一个元素上同时使用 onclick 和 ondblclick?
For more information about what delay you should use for your timer, have a look here : How to use both onclick and ondblclick on an element?
这篇关于D3:如何设置“点击"?事件和“dbclick"同时举办活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:D3:如何设置“点击"?事件和“dbclick"同时举办活动?


基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01