Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个附加到父元素的侦听器,在函数中我想知道点击是否发生在图像子元素上。
function onClick(evt) { if (evt.target === ?)
我尝试将目标与 HTMLImageElement 进行比较。
你可以看一下tagName楼盘:
tagName
var tag = event.target.tagName; if (tag == 'BUTTON') { ... }
请记住,对于 IE,您需要srcElement:
srcElement
var elem = event.target || event.srcElement || { tagName: "?" }; var tag = elem.tagName;