引用:http://www.pocketdigi.com/category/javascript-ajax
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> function add(){ var a=document.getElementById("p"); a.innerHTML+="点了"; if(window.event){ p.detachEvent("onclick",add);//删除IE监听函数 }else{ p.removeEventListener("click",add,false);//删除Firefox监听函数 } } var p; window.onload=function(){ p=document.getElementById("p"); if(window.event){// 如果是IE,用attachEvent绑定onclick事件,执行add函数 p.attachEvent("onclick",add); }else{//否则用addEventListener绑定 p.addEventListener("click",add,false);//false表示为冒泡型,非捕获型 } } </script> </head> <body> <div> <p id="p">点我</p> </div> <p id="change"></p> </body> </html>