Real-time listening of input boxes

Source: Internet
Author: User

I. There are three methods:

1. onchange ()

2. oninput ()

3. onpropertychange ()

2. onchange ()

This event monitors whether the input value changes. However, it is only triggered when the input box loses focus, and is valid in browsers such as IE, chrome, and Firefox.

3. oninput () & onpropertychange ()

If you want to trigger the input box as long as the value changes without losing focus, this is what you need to be a good friend.

Oninput () & onpropertychange () is applicable to different browsers. oninput () is used in non-ie browsers, while onpropertychange () is used in IE browsers ().

Oninput () & onpropertychange () can be triggered for operations such as keyboard input, cut copy, and cancel redo operations. However, oninput () does not trigger a value assignment to Js, however, onpropertychange () can be triggered by assigning values to Js.

4. Use instances

 1  1 <input type="text" oninput="changeEvent();" onpropertychange="changeEventIe(event);"> 2  2 //触发的事件 3  3 function changeEvent(){ 4  4     //do what u want to do 5  5 } 6  6  7  7 function changeEventIe(event){ 8  8     //判断改变的是否是input的value属性 9  9     if(event.propertyName != ‘value‘) return;10 10     //do what u want to do11 11 12 12 }

 

real-time listening of input boxes

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.