当文本框的值发生改变时,触发事件,在IE中有效

 

<!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>
  
<title> new document </title>
  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="msg"></div>
<input id='txt' value="" />
<input id='btn' value="dsa" type="button" onclick="ff()" />
<script>
//当状态改变的时候执行的函数
function handle()
{
    document.getElementById(
'msg').innerHTML = "输入的文字为:" + document.getElementById('txt').value;
}


if(/msie/i.test(navigator.userAgent))    //ie浏览器
{
    document.getElementById(
'txt').onpropertychange = handle;
}

else
{//非ie浏览器,比如Firefox
    document.getElementById('txt').addEventListener("input", handle, false);
document.getElementById(
'txt').watch('a', fn); 
}


function ff()
{
document.getElementById(
'txt').value=Math.random();
}

</script>
</body>
</html>

 

posted @ 2009-09-03 00:25  清凉一夏  阅读(3679)  评论(0)    收藏  举报