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

  作者:bea

<!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> <me


<!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>




[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]



有用  |  无用

猜你喜欢