随笔-103  评论-37  文章-0  trackbacks-0

当一个HTML元素的属性用js改变的时候,都能通过 onpropertychange来捕获。例如一个 <input name="text1" id="text1" />对象的value属性被页面的脚本修改的时候,onchange无法捕获到,而onpropertychange却能够捕获。
也就是说:
onpropertychange事件在用键盘每改变一下文本框的值或用js改变其值便会触发一下,而onchange只有在用键盘改变其值,然后在失去焦点(onblur)后才触发,用js改变其值不能触发!onpropertychange和onchange都不管文本框中的实际值有没有变,只要有改的相应操作就可能触发。有时当上面两时间都不能满足需求时,可以考虑只用onblur。

还有一点要注意到,当onblur和onchange事件一起用时,onblur会出问题。。。。

最近用onpropertychange做了一个效果,很好用。 点击一个复选框让其他复选框全选中。

  <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
    
<tr>
      
<td> <input type="checkbox" name="cheeckbox1" id="cheeckbox1"  onpropertychange="checkbox2.checked=this.checked;checkbox3.checked=this.checked;checkbox4.checked=this.checked;checkbox5.checked=this.checked;"/> 1 </td>
      
<td>&nbsp;</td>
    
</tr>
    
<tr>
      
<td> <input type="checkbox" name="checkbox2" id="checkbox2" /> 2</td>
      
<td>&nbsp;</td>
    
</tr>
    
<tr>
      
<td> <input type="checkbox" name="checkbox3" id="checkbox3" /> 3</td>
      
<td>&nbsp;</td>
    
</tr>
    
<tr>
      
<td> <input type="checkbox" name="checkbox4" id="checkbox4" /> 4</td>
      
<td>&nbsp;</td>
    
</tr>
    
<tr>
      
<td> <input type="checkbox" name="checkbox5" id="checkbox5" /> 5</td>
      
<td>&nbsp;</td>
    
</tr>
  
</table>
posted on 2008-07-30 17:45 鱼有所思 阅读(933) 评论(0)  编辑 收藏 引用 网摘 所属分类: AJAX

只有注册用户登录后才能发表评论。
网站导航: