要想了解onpropertychange,就必须结合onchange一起来讲。
当一个HTML元素
属性改变
时候
都能通过 onpropertychange来捕获
例如一个 <input name="text1" id="text1" />对象
value属性被页面
脚本修改
时候
onchange无法捕获到
而onpropertychange却能够捕获
也就
说:onpropertychange能及时捕获属性值
变化
而onchange
属性值改变时还必须使得当前元素失去焦点(onblur)才可以激活该事件!
看下面一个例子:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function doChange(){
//alert("length="+document.getElementById("mytable").rows.length);
alert("value is changed");
}
function doProChange(){
//alert("length="+document.getElementById("mytable").rows.length);
alert("hahaaha");
}
</script>
</head>
<body>
<input type="text" value="" onchange="doChange();" onpropertychange="doProChange();" />
</body>
</html>
每当输入一个字符时,就会触发onpropertyChange事件,打印hahaaha,但是只有等焦点离开了,才会打开value is changed.
本文深入探讨了HTML元素属性改变时onpropertychange与onChange事件的区别,并通过实例展示了如何使用onpropertychange及时捕获属性值的变化。特别强调了onpropertychange在属性值改变时不需元素失去焦点即可激活的特点。

10万+

被折叠的 条评论
为什么被折叠?



