The getAttributeNode () method is used here. It obtains attribute nodes and ignores the differences between attributes and events. The specific example is as follows, if you are interested, you can refer to the following: I hope to help you. When you are dealing with the drop-down menu cascading problem, you want to get the content of an event in the HTML Tag, that is, the value, for example, from To obtain javascript: test ();.
The dish wants to determine the next menu through the information in the event, but this seemingly simple problem makes the dish tangle.
If you have a little understanding of JQuery, you may try to get it like this:
The Code is as follows:
$ (Document). ready (function (){
Var onchangeValue = $ ("# city"). attr ("onchange ");
Alert (onchangeValue );
});
In general, this can be obtained, because JQuery's omnipotent attr method can be used to obtain any "attribute" in the tag. Even if it is an event, the content can be directly obtained, here onchange is an event.
However, in the actual development environment, this method cannot be obtained, and all the results are undefined.
During the tangle, we found another method to implement acquisition using pure JavaScript.
The Code is as follows:
The Code is as follows:
$ (Document). ready (function (){
Var onchangeValue = document. getElementById ("city"). getAttributeNode ("onchange"). nodeValue;
Alert (onchangeValue );
});
To put it simply, the getAttributeNode () method is used here. It obtains attribute nodes and ignores the differences between attributes and events, similar to XML processing, then, use nodeValue to obtain the node value of the attribute node.
If the getAttribute () method is used, because onchange is an event, a function object is obtained and cannot be processed as a string.
I hope this article will help the children's shoes.