本文介绍了html body ondblclick获取被点击的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以在我的html中,我有这部分:
so in my html i have this portion:
<body ondblclick="myfunc();">
<div id="id1">dasd</div>
<div id="id2">dasda</div>
</body>
并且在javascript中,功能是:
and in javascript the function is :
function myfunc() {
do stuff here...
}
我想知道在myfunc()内部是在doublebody的哪个HTML元素上进行的,因为我不想在每个doubleclicked元素上触发myfunc()
i want to know inside myfunc() on which element of the html body the doubleclick was made, because i don't want to triger myfunc() on every doubleclicked element
那么如何检测双击元素的ID?
so how can i detect the id of the element doubleclicked?
推荐答案
<body ondblclick="myfunc(event);">
function myfunc(e) {
// e.target -> element that was clicked
}
这篇关于html body ondblclick获取被点击的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!