How js triggers the onchange Event _ javascript skills

Source: Internet
Author: User
In js Code mode, how does one trigger the onchange event of the textbox Control through code? after reading the materials, it is found that js provides a method, the onchange event in all event js triggers the control to change the value of the input control on the client side, such as a textbox, which will trigger an event. However, if you change the value of a textbox In the js Code, instead of entering a textbox value through the keyboard, the onchange event will not be initiated.

In the js Code mode, how does one trigger the onchange event of the textbox Control through code? after reading the information, it is found that js provides a method to trigger all events of the control. The object. fireEvent () method, such as object. fireEvent ('onchange'), can trigger the onchange event of the control.

Similarly, using the fireEvent method in js can also trigger other spatial events.

• AddThe above fireEvent method is not supported in the firefox browser. If you want to run both ie and ff, try the following code.

The Code is as follows:


If (obj. fireEvent)
{
Obj. fireEvent ('onchange ');
}
Else
{
Obj. onchange ();
}


That is to say, determine whether the fireEvent event is available. If it is unavailable, use the onchange () method directly.

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.