例子,当文本框的值发生改变时,触发事件,在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>文本框事件-www.jb200.com</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>