Js/jquery the perfect solution for real-time monitoring of changes in input frame values: Oninput & Onpropertychange

Source: Internet
Author: User

This article is reproduced in http://blog.163.com/lgh_2002/blog/static/44017526201341511112874/

 jquery binding events (the difference between bind and live) Js/jquery the perfect solution for real-time monitoring of changes in input frame values: Oninput & OnpropertychangeJs/jquery the perfect solution for real-time monitoring of changes in input frame values: Oninput & Onpropertychange

2013-05-15 11:01:12  |  Category: Jquery/javascrip | Tags: | report | font size big medium small Subscribe

(1) First of all, jquery, using the jquery Library, only need to bindon input and Onpropertychange two events on the same time, the sample code: $( ‘#username‘ ).bind( ‘input propertychange‘ , function () {      $( ‘#content‘ ).html($( this ).val().length + ‘ characters‘ ); }); (2) for JS native notation, Oninput is the standard event for HTML5 , for detection textarea, Input:text, Input:password and input:search these elements through the user The content changes that occur in the interface are very useful, and are triggered immediately after the content has been modified, unlike the onchange event that needs to lose focus. the compatibility of Oninput events in mainstream browsers is as follows:

  

 As can be seen from the table above, theoninput event is not supported in the following versions of IE9 and requires the use of IE-specific Onpropertychange event substitution, which is triggered when the user interface changes or the content is modified directly using a script. There are several situations:

    • Modified the Input:checkbox or Input:radio element selection state, the checked attribute changed.
    • The value of the Input:text or TEXTAREA element has been modified, and the property of value has changed.
    • The selected item of the SELECT element has been modified, and the SelectedIndex property has changed.

After you hear the onpropertychange event, you can use the PropertyName property of the event to get the name of the property that has changed.

The sample code for collection Oninput & onpropertychange monitoring input box content changes is as follows:

12 3<script type="Text/javascript">4     //Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 95function Oninput (Event) {6Alert ("The new content:"+Event. Target.value);7         }8     //Internet Explorer9function onpropchanged (Event) {Ten             if(Event. propertyname.tolowercase () = ="value") { OneAlert ("The new content:"+Event. Srcelement.value); A             } -         } -</script> the -<body> - Please modify the contents of the text field. -<input type="text"oninput="Oninput (Event)"Onpropertychange="onpropchanged (Event)"Value="Text Field"/> +</body>

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.