Home >Web Front-end >JS Tutorial >event.srcElement usage notes e.target_javascript tips

event.srcElement usage notes e.target_javascript tips

WBOY
WBOYOriginal
2016-05-16 18:38:481241browse

Note that the obtained tags are all expressed in uppercase letters, such as "TD", "TR", "A", etc. So I copy down some of what I’ve read and come back to it when I don’t remember.

Copy code The code is as follows:



event.srcElement literally has the following keywords: event, source It means: the source of the current event.
We can call its various attributes such as: document.getElementById("").
People often ask how to use event.srcElement under firefox. This detailed description:
Under IE, the event object has the srcElement attribute, but no target attribute; under Firefox, the event object has the target attribute, but no srcElement attribute. But their functions are equivalent, that is:
Under firefox event.target = event.srcElement under IE

Solution: use obj (obj = event.srcElement ? event.srcElement : event.target;) to replace event.srcElement under IE or Firefox event.target.
The following are some common situations (the test passes under IE. If you want to test event.target under firefox, you can modify and save the code and then open the test with firefox):

event. srcElement. div id="div_001">
<script> </u>function Get_srcElement() </a>{ </span>var srcElement="" </div>srcElement = srcElement " " " event.srcElement.id : " event.srcElement.id <div class="codebody" id="code36405">srcElement = srcElement " " " event.srcElement.tagName : " event.srcElement.tagName <br>srcElement = srcElement " " "event.srcElement.type : " event.srcElement.type <br>srcElement = srcElement " " "event.srcElement.value : " event.srcElement.value <br>srcElement = srcElement " " "event .srcElement.name : " event.srcElement.name <br>srcElement = srcElement " " " event.srcElement.className : " event.srcElement.className <br>srcElement = srcElement " " " event.srcElement.parentElement.id : " event.srcElement.parentElement.id <br>srcElement = srcElement " " "event.srcElement.getattribute : " event.srcElement.getAttribute <br>alert(srcElement) <br>} <br></script>


event.srcElement.selectedIndex is generally used on select objects:




Copy code


The code is as follows:

The first sub-tag The last one is
event.srcElement.firstChild
[i]
As for event.srcElement.parentElement, it refers to the previous object of the object where the mouse is located.




Copy code

The code is as follows:


< ;span id="node001">This is the first node div001
This is the second node div002
This is the third node div003

This is the third node div004


< ;/div>
<script> <br>function Get_srcElement() <br>{ <br>var srcElement="" <br>srcElement = srcElement " " "event.srcElement.children[0].tagName: " event.srcElement.children[0].tagName <br>srcElement = srcElement " " " event.srcElement.firstChild.id : " event.srcElement.firstChild.id <br>srcElement = srcElement " " " event.srcElement.lastChild .id : " event.srcElement.lastChild.id <br>alert(srcElement) <br>} <br></script>






event.srcElement related issues - - The child tags and parent tags of
event.srcElement:
The first child tag is
event.srcElement.firstChild
The last one is
event.srcElement.lastChild
Of course, you can also use
event.srcElement.children[i]
event.srcElement.ChildNode[i]
As for event.srcElement.parentElement, it refers to the previous object of the object where the mouse is located.


atest



< ;td>tr



td


Code reference:
http://www.jb51.net /article/566.htm
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:javascript export data to Excel (process elements in table)_javascript skillsNext article:javascript export data to Excel (process elements in table)_javascript skills

Related articles

See more