Triggering events about the change of input content

Source: Internet
Author: User

1, onchange

The onchange event is triggered when the content of the domain changes. Supported labels <input type= "text", <textarea>, <select>,<keygen>. NOTE: Triggers when the value of the element has changed and loses focus (the value of two times does not fire). Defect: The value of DOM changed by JS code will not be triggered, the change in JS code to call its change function ()or adjust the. Change () method. Js:
1 <inputtype="text" id="cash" onchange="function()">

Jquery:

1 $("#cash").change(function(){});

2, Onpropertychange

The onpropertychange is triggered in real time, triggering events as the attributes of the element change. Does not fire when an element is disable=true. Defects: Only under IE support, other browsers do not support, with oninput to solve. Js:
1 <inputtype="text" id="cash" onpropertychange="functionName()">

3, Oninput

Oninput is triggered when the value of <input> or <textarea> changes, and does not need to wait until the element loses focus and is in real time. It is a HTML5 event that can be used to detect the value of a text class input box. Defect: Modifying a value from a script does not trigger an event. Selecting a value from the browser drop-down prompt does not trigger. IE9 below are not supported, so IE9 can be replaced with Onpropertychange events below. Solution: Change the DOM value by JS Code does not trigger, solve in the JS code changed the value of the call its oninput functionname ()Method. Js:
1 <inputtype="text" oninput="functionName()">

Jquery:

1 $("#cash").on(‘input propertychange‘,functionName);

4, AddEventListener

AddEventListener () is used to add an event method to the specified element. Use RemoveEventListener () to remove the added event method. IE9 below is not supported, replace with Attachevent.

Syntax: element. AddEventListener (event, function, Usecapture)

---------------------------------------------------

How to allow input to enter only numbers:

Onkeyup= "Value=value.replace (/[^\d]/g, ')"

Triggering events about the change of input content

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.