Home > Web Front-end > JS Tutorial > Description of the method of triggering the onchange event in js_javascript skills

Description of the method of triggering the onchange event in js_javascript skills

WBOY
Release: 2016-05-16 16:56:20
Original
1463 people have browsed it

The onchange event in js is an event that is triggered when the value of an input control, such as a textbox, is changed on the client side. But if you change the value of a textbox in js code instead of changing the value of a textbox through keyboard input, the onchange event will not be triggered.

So, how to trigger the onchange event of the textbox control through code in js code mode? After consulting the information, I found that js provides a method that can trigger all events of the control. object.fireEvent() method, use methods such as object.fireEvent('onchange') to trigger the onchange event of the control.

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

•To add , the above fireEvent method is not supported in the Firefox browser. So, if you want to run it in both IE and FF, try the following code .

Copy code The code is as follows:

if (obj.fireEvent)
{
obj.fireEvent('onchange');
}
else
{
obj.onchange();
}

That is, determine the fireEvent event Whether it is available, if not, use the onchange() method directly.
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template