"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> functionset() { varobj = document.getElementById("fy"); //obj.attachEvent('onfocus', add); //在原先事件上添加 //obj.setAttribute('onfocus',add); //会替代原有事件方法 //obj.onfocus=add; //等效obj.setAttribute('onfocus',add); if(window.addEventListener) { //其它浏览器的事件代码: Mozilla, Netscape, Firefox //添加的事件的顺序即执行顺序 //注意用 addEventListener 添加带on的事件,不用加on obj.addEventListener('focus', add,false); }else{ //IE 的事件代码 在原先事件上添加 add 方法obj.attachEvent('onfocus', add); } } functionadd() { alert("已经成功添加事件"); } |