对具有该元素的元素执行 DoubleClick [英] Perform DoubleClick on element that have that

查看:18
本文介绍了对具有该元素的元素执行 DoubleClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看这里:

从显示我元素具有双击dblclick"事件的一页

that from One page that show me that element have event of doubleclick "dblclick"

但是当我尝试从控制台执行它时:

but when i try to perform it from console:

推荐答案

dblclick 不是方法,而是一种事件.假设您有一个按钮,并且您想手动触发该事件.你可以这样做.

dblclick is not a method, it is a type of event. Let's say you have a button, and you wanted to manually fire that event. You could do so like this.

<button id='myButton'>Click Me!</button>

现在你可以这样做了

var evt = new Event('dblclick');
var button = document.getElementById('myButton');
// This is where the magic happens
button.dispatchEvent(evt);

这会手动触发 dblclick 事件.您必须在 dom 节点上调用dispatchEvent",并且它需要一个Event"对象.

This manually fires the dblclick event. You must call 'dispatchEvent' on a dom node, and it takes an 'Event' object.

对于您的用例,只需将 'button' 元素替换为您自己的 'a' 变量,它就会按预期工作.

For your use case, just replace the 'button' element with your own 'a' variable, and it should work as expected.

这篇关于对具有该元素的元素执行 DoubleClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆