Tips for triggering the select onchange event in js: selectonchange

Source: Internet
Author: User

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.