This article describes the method of detecting which HTML tag in the page triggers the click event. Share it for your reference, as follows:
In the html tag, for the beautiful display of the page, they will be nested in the tags, and various events will inevitably be added when making "effects", such as:
<a href=""><span onclick="">dddd</span></a>
When the user clicks, he wants to determine whether it is an event generated by the link or an event generated by the span tag onclick tag. This is sometimes very necessary. At least I think it is useful during debugging, so I wrote a simple demo for everyone to learn.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><script type="text/javascript">//Get the control function that triggers the event test(obj){//The following method is used to detect which space triggers the event alert(window.event.srcElement.tagName);}</script><title>Untitled Document</title></head><body> <input type="button" value="test" onclick="test(this)"/> <button type="button" value="test" onclick="test(this)">ddddd</button> <span type="button" value="test" onclick="test(this)">span</span></body></html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.