事件触发顺序:

onkeydown

onkeypress

onkeyup

注意: onkeypress 事件在所以浏览器中不能触发所有按键(例如:ALT, CTRL, SHIFT, ESC) 。如果只对用户是否已经按下一个按键检测, 可以使用 onkeydown 取代, onkeydown被所有按键触发。


onpropertychange能够捕获每次输入值的变化。例如:对象的value值被改变时,onpropertychange能够捕获每次改变。


//当状态改变的时候执行的函数

function handle() {

alert("f");

}

//firefox下检测状态改变只能用oninput,且需要用addEventListener来注册事件。

if (/msie/i.test(navigator.userAgent)) //ie浏览器

{

document.getElementById("cc").onpropertychange = handle

} else {//非ie浏览器,比如Firefox

document.getElementById("cc").addEventListener("input", handle, false);

}



function getOs(){//判断浏览器类型  

   var OsObject = "";  

  if(navigator.userAgent.indexOf("MSIE")>0) {  

       return "MSIE";  

  }  

  if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){  

       return "Firefox";  

  }  

  if(isSafari=navigator.userAgent.indexOf("Safari")>0) {  

       return "Safari";  

  }  

  if(isCamino=navigator.userAgent.indexOf("Camino")>0){  

       return "Camino";  

  }  

  if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){  

       return "Gecko";  

  }  


}  


if(navigator.userAgent.indexOf("MSIE")>0){  

document.getElementById('tx1').attachEvent("onpropertychange",txChange);  

}else if(navigator.userAgent.indexOf("Firefox")>0){  

   document.getElementById('tx1').addEventListener("input",txChange2,false);  

}  

function txChange(){  

   alert("testie");  

}  

function txChange2(){  

   alert("testfirefox");  

}  

http://t.cn/8ssUEwA