Invalid solutions for onchange and onpropertychange of onchange in js

  • 2020-03-30 02:18:20
  • OfStack

The author's note: Today, I did not get any reaction when I used the event of onchange. At last, I searched the data to find out the limitations and instability of onchange. Onpropertychange, however, can be well implemented, especially its real-time capture performance, which is well worth using. .

I am also relatively lazy, their own things are lazy down only to search the original version of the information to share with you:

Under IE, when a property of an HTML element changes, it can be captured through onpropertychange. For example, an

< The input name = "text1" id = "text1" / >

Onchange cannot be captured when the value property of the object is modified by the script of the page, while onpropertychange can be captured. (captured in real time)

That is to say: onpropertychange can catch the change of property value in time, and onchange must make the current element lose focus (onblur) when the property value changes to activate the event!

Such as:

Case 1:

Please enter the picture address: < Input type="text" name="mytext" size="10" value="" onpropertychange="document.images['myimg'].src=this.value;" / > < Img id="myimg" SRC ="/img/common/logo.gif" Alt ="/ >

When the contents of the text box are changed, the image is immediately displayed. However, if you use onchange, you still need to click the blank or other place to make the input element lose the focus to activate the event and the image display will be changed!

Example 2:

< INPUT the id = "image" style = "WIDTH: 448 px; HEIGHT: 22 px "        Onpropertychange ="preview. SRC =image.value" type="file" size="55" name="File1" runat="server">

< IMG id="preview" height="170" Alt =" SRC =" width="256">


The onpropertychange event was so cute that I fell in love with it at first sight

OnChange: the event triggered by the current element losing focus and the element's content changing

Therefore, the onChange event will not be triggered when the value of the object is changed by the script, because the user neither moves the mouse nor the keyboard.

Related articles: