日期:2014-05-16 浏览次数:20501 次
<!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>JS</title> </head> <body> <input id="para" type="text" /> <script type="text/javascript"> function test(){ alert("test"); } function pig(){ alert("pig"); } window.onload = function(){ var element = document.getElementById("para"); if(element.addEventListener){ // firefox , w3c element.addEventListener("focus",test,false); element.addEventListener("focus",pig,false); } else { // ie element.attachEvent("onfocus",test); element.attachEvent("onfocus",pig); } } </script> </body> </html>
document.getElementById("btn").onclick = method1; document.getElementById("btn").onclick = method2; document.getElementById("btn").onclick = method3;如果这样写,那么将会只有medhot3被执行
var btn1Obj = document.getElementById("btn1"); //object.attachEvent(event,function); btn1Obj.attachEvent("onclick",method1); btn1Obj.attachEvent("onclick",method2); btn1Obj.attachEvent("onclick",method3);执行顺序为method3->method2->method1
1。 var el = EDITFORM_DOCUMENT.body; //先取得对象,EDITFORM_DOCUMENT实为一个iframe if (el.addEventListener){ el.addEventListener('click', KindDisableMenu, false); } else if (el.attachEvent){ el.attachEvent('onclick', KindDisableMenu); }2。 if (window.addEventListener) { window.addEventListener('load', _uCO, false); } else if (window.attachEvent) { window.attachEvent('onload', _uCO); } detachEvent和removeEventListener Js代码 detachEvent('onclick',func);//ie下使用删除事件func removeEventListener('click',func);//Mozilla下,删除事件func