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);
});
To put it simply, this is the main use of the GetAttributeNode () method, it gets the attribute node, ignoring the difference between the properties and events, similar to the processing of XML, and then use 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 can help the children's shoes that need ....