<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>通过js改变文本框中的值后触发的事件:onpropertychange事件 </title> </head> <body> <div id="test1"> <b>测试onpropertychange事件和onchange事件一起用时: </b> <br> <font color="red">测试结果:onpropertychange事件在用键盘每改变一下文本框的值或用js改变其值便会触发一下,而onchange只有在用键盘改变其值,然后在失去焦点后才触 发,用js改变其值不触发 </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>测试只有onblur和onchange事件时: </b> <br> <font color="red">测试结果:onchange先触发,onblur后触发 </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>测试当onblur和onpropertychange事件一起用时: </b> <br> <font color="red">测试结果:onblur好象出了问题,只要用键盘在文本框中随便输入一个值,便会触发它。可能是onpropertychange把它惹毛了。。。^-^ </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>测试有onblur、onpropertychange事件和onchange事件一起用时: </b> <br> <font color="red">测试结果:onblur在和onpropertychange一起用时的问题仍然存在 </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>
JS中onpropertychange和onchange事件区别小结
原文:http://www.cnblogs.com/imsoft/p/4923033.html