Tips for triggering the select onchange event in js: selectonchange
The onchange event of select or text can be triggered only by Manually changing the value of select or text (input through the keyboard). If select or text is assigned to js, The onchang event cannot be triggered,
For example, after loading the page, you need to trigger an onChange event and use document. getElementById ("province "). value = "Hubei"; it is not acceptable to assign values to select or text directly. to manually trigger the onchange event, add the following statement after js assigns values to select.
Document. getElementById ("province"). fireEvent ('onchange') to implement,
<Head> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <title> untitled document </title> <script type =" text/javascript "> var provinces = new Array (); provinces ["Hubei"] = ["Wuhan", "Xiangyang", "Suizhou", "Yichang", "Shiyan"]; provinces ["Sichuan"] = ["Chengdu", "Neijiang", "dazhou"]; provinces ["Henan"] = ["Zhengzhou", "Nanyang ", "Xinyang", "Luohe"]; function changeProvince () {var prov = document. getElementById ("province "). value; var city = document. getElementById ("city"); city. options. length = 0; for (var I in provinces [prov]) {city. options. add (new Option (provinces [prov] [I], provinces [prov] [I]) ;}} window. onload = function () {var province = document. getElementById ("province"); for (var index in provinces) {// alert (index); province. options. add (new Option (index, index);} province. fireEvent ("onchange") ;}; </script>
How to call the select onchange () event using js
?? ?? ?? ?? A (); I omitted it and did not write it ;?? Function ?? A () {alert ("11 ");}?? ?? ??
Back: ywb1973 (WHO )(★☆◎ ☆★)??
?? ?? ?? Document. getElementById ("a"). onchange (); cannot be deleted. My goal is to call a () through this sentence; but the list value has changed and the event is not triggered
This statement is already called a (). You can call onchange IN a () again, which is incorrect.
If you write this document. getElementById ("a"). onchange ();, you will always recursively call yourself, and an error will occur: Stack ?? Overflow
Recommended: 0 times help? Please recommend JScript code a B c. How can I use js to trigger the select onchange event? Please recommend
Js dynamically creates select and assigns onchange events
MySelect. addEventListener ('change', function (){
Return mychange. apply (this, [this. value, pid, num]);
});
Several links are recommended.
Developer.mozilla.org/en/Core_JavaScript_1.5_Guide
Ejohn.org/
Quirksmode.org/