Here is the main use of the GetAttributeNode () This method, it gets the attribute node, ignoring the difference between the properties and events, such as, for example, interested friends can refer to the HA hope to be helpful to everyone
Today the side dishes handle Pull-down menu cascading problems, want to get the content of an event in the HTML tag, that is, the value, such as from <select id= "City" onchange= "Javascript:test ();" ></select> get Javascript:test ();.
Small dishes want to pass the information in the event to determine the next level of the menu, but this seemingly simple question, but let the side of the cake tangled.
A little bit of jquery's kid's shoes might try to get this:
Copy Code code as follows:
$ (document). Ready (function () {
var onchangevalue = $ ("#city"). attr ("onchange");
alert (onchangevalue);
});
In general, this can indeed be obtained, because the jquery universal attr method, can get any "properties" in the label, even an event, you can directly get content, here onchange is the event.
But the side dishes in the actual development environment, with this method how also cannot obtain, obtains is the undefined.
In the tangle, another method of using pure JavaScript to achieve the acquisition was found.
The specific code is as follows:
Copy Code code as follows:
$ (document). Ready (function () {
var onchangevalue = document.getElementById ("City"). GetAttributeNode ("onchange"). NodeValue;
alert (onchangevalue);
});
Simply put, here is the GetAttributeNode () method, which gets the attribute node, ignoring the difference between the property and the event, similar to the processing of XML, and then using NodeValue to get the node value of the attribute node.
If you use the GetAttribute () method, because OnChange is an event, you get a function object that cannot be treated as a string.
I hope this article will help you with the children's shoes.