Onpropertychange and onchange events in JS

Source: Internet
Author: User
Tip: you can modify some code before running

<html> <head> <title>Event triggered after the value in the text box is changed through js: onpropertychange event</title> </head> <body> <div id="test1"> <b>When the onpropertychange event and onchange event are tested together:</b> <br> <font color="red">Test results: the onpropertychange event is triggered when the value of the text box is changed or the value of the text box is changed using js. The onchange event is triggered only when the value of the text box is changed using the keyboard, trigger after the focus is lost, and use js to change its value does not trigger</font> <br> <input name="haha1" type="text" onpropertychange="alert('触发了onpropertychange事件!')" onchange="alert('触发了onchange事件!')" size="30" > <input name="testbutton1" value="通过js改变文本框中的值" type="button" onclick="document.getelementbyid('haha1').value='js改变文本框后的值'"> <br><br> <br> <div id="test2"> <b>When only onblur and onchange events are tested:</b> <br> <font color="red">Test result: onchange is triggered first, and onblur is then triggered.</font> <br> <input name="haha2" type="text" onblur="alert('触发了onblur事件!')" onchange="alert('触发了onchange事件!')" size="30" > <input name="testbutton2" value="通过js改变文本框中的值" type="button" onclick="document.getelementbyid('haha2').value='js改变文本框后的值'"> <br> <div> <br><br> <br> <div id="test3"> <b>Test when onblur and onpropertychange events are used together:</b> <br> <font color="red">Test result: onblur seems to have a problem. If you enter a value in the text box on the keyboard, it will be triggered. It may be that onpropertychange makes it messy... ^-^</font> <br> <input name="haha3" type="text" onblur="alert('触发了onblur事件!')" onpropertychange="alert('触发了onpropertychange事件!')" size="30" > <input name="testbutton3" value="通过js改变文本框中的值" type="button" onclick="document.getelementbyid('haha3').value='js改变文本框后的值'"> <br> <div> <br><br> <br> <div id="test4"> <b>When onblur, onpropertychange, and onchange events are used in the test:</b> <br> <font color="red">Test results: the onblur and onpropertychange problems still exist.</font> <br> <input name="haha4" type="text" onblur="alert('触发了onblur事件!')" onpropertychange="alert('触发了onpropertychange事件!')" onchange="alert('触发了 onchange事件!')" size="30" > <input name="testbutton4" value="通过js改变文本框中的值" type="button" onclick="document.getelementbyid('haha4').value='js改变文本框后的值'"> <br> <div> </body> </html>
Tip: you can modify some code before running

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.