OnChange and Onpropertychange in JS

Source: Internet
Author: User

  This article mainly introduces the onchange and Onpropertychange in JS (onchange Invalid solution), the need for friends can come to the reference, I hope to help you.

I note: Today I use the onchange event without any reaction, and finally look at the data to know onchange limitations and instability. And Onpropertychange is very good, especially its real-time capture performance is very worthwhile to use (thanks to this performance, to make things the boss is satisfied with O (∩_∩) o ... )。   I am also lazy, I do things are lazy to clean up the search to the original information to share with you:   IE, when an HTML element of the property changes, can be captured by Onpropertychange. For example, the Value property of a     <input name= "Text1" id= "Text1"/>   object is modified by the script of the page, onchange cannot be captured. And Onpropertychange can capture it. (is captured in real time)   that is to say: Onpropertychange can capture the changes in property values in time, and onchange when the value of the property changes must also cause the current element to lose focus (onblur) to activate the event!   such as:   Example 1:   Please enter picture address: <input type= "text" name= "mytext" size= "" value= "" onpropertychange= "document.im ages[' myimg '].src=this.value "/> <img id=" myimg "src="/img/common/logo.gif "alt=" "/>   when the contents of the text box are changed, The picture will be displayed immediately. If you use onchange, change the value of the mouse click white space or other places to make the INPUT element lose focus (onblur) to activate the event, the picture will be changed!   Example 2:   <input id= "image" style= "width:448px; height:22px "    onpropertychange=" Preview.src=image.value "type=" file "size=" "Name=" File1 "runat=" Server >   <img id= "Preview" height= "170" alt= "" src= "" Width= "256" >  ----------------------------------------------------------------  Onpropertychange event is so cute, I love it at first sight   OnChange: event that the current element loses focus and the content of the element changes to trigger events [mouse and keyboard triggers can be]   So when the value of the object is changed by the script, it does not trigger the onchange event, because the user does not move the mouse and does not move the keyboard.  

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.