日期:2014-05-16  浏览次数:20350 次

这个问题比较难,问了好多人都不知道
html的text的onchange是当值改变并失去焦点时触发的.

我现在需要的是,只要当text的值改变,就触发。

text的值一般有两种改变方法,
1,是人为输入,这个简单,onkeypress就可以扑获
2,方法改变,比如在某按钮中用语句   text.value= "xxxx ",也可以改变text的value,这时候就扑获不到text的值改变了.

希望有人可以帮忙

------解决方案--------------------
用onpropertychange即时捕获~
------解决方案--------------------
lz看下面这样可以吗?
*************** onkeypress事件+value判断 *********************

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<script>
function resetKwValue()
{
var keyword = document.getElementById( "keyword ").value;

if(keyword == "查询关键字 ")
{
document.getElementById( "keyword ").value = " ";
}
else
{
alert( "值已改变,触发 ");
}
}
</script>
</head>

<body>
<input type= "text " id= "keyword " value= "查询关键字 " onkeypress= "resetKwValue(); "/>
</body>
</html>
------解决方案--------------------
这样,貌似只有定时读取判断了!
页面载入时写入变量该控件初始值,然后再定时判断吧!
------解决方案--------------------
FF 用 oninput
IE 用 onpropertychange