当前位置: 代码迷 >> Web前端 >> onchange与onpropertychange的联系与差别
  详细解决方案

onchange与onpropertychange的联系与差别

热度:12   发布时间:2012-11-08 08:48:11.0
onchange与onpropertychange的联系与区别

当一个HTML元素的属性改变的时候,都能通过onpropertychange来捕获。例如一个<input />对象的value属性被页面的脚本修改的时候,onchange无法捕获到,而onpropertychange却能够捕获。

具体理解为:onpropertychange能及时捕获属性值的变化,而onchange在属性值改变时只有通过鼠标执行某些操作才能激活该事件!

上传图片立刻显示时经常用到,脚本改变<input />对象的value值时,可用onpropertychange事件。

 

 

<table width="200" border="1">
<form action="savetry.asp" method="post">
  <tr>
    <td><input type="text" /></td>
  </tr>
  <tr>
    <td><input type="text" /></td>
  </tr>
  <tr>
    <td>
 <img src='../upimg/1.jpg' border="0" />
 <input type='file' onpropertychange="document.getElementById('TestImg').src=this.value;" /> 
          <input readonly="" type="text"  class="wenbenkuang" size="28" onpropertychange="document.getElementById('TestImg').src='../'+this.value;">
          <a href=# ../upfilepic_get.asp?formname=guanggao&editname=guang_1&uppath=upimg&filelx=jpg','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')">上传图片</a>    
    
 </td>
  </tr>
  <tr>
    <td><input type="submit" /></td>
  </tr>
</form>
</table>
?