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

mac2022-06-30  82

 

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

 

转载于:https://www.cnblogs.com/windthunder/archive/2009/09/03/1559196.html

最新回复(0)