当文本框的值发生改变时,触发事件,在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需刷新才能执行]
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- Javascript String.replace的妙用
- Javascript 检测、添加、移除样式(className)函数代码
- Javascript 阻止浏览器默认操作的实现代码
- javascript 流畅动画实现原理
- javascript 定义初始化数组函数
- JS 网页彩蛋 实现代码
- javascript十个最常用的自定义函数(中文版)
- javascript 获取select下拉列表值的代码
- Javascript中的var_dump函数实现代码
- jquery tools系列 expose 学习
- jquery tools系列 overlay 学习
- jquery tools 系列 scrollable(2)
- jquery tools 系列 scrollable学习
- javascript事件问题
- js跨域和ajax 跨域问题的实现思路
- JavaScript 密码强度判断代码
- 关于javascript中的parseInt使用技巧
- jquery判断单个复选框是否被选中的代码
- javascript 操作table的特性