function addEvent(el ,type ,fn){ if(el.addEventListener){ el.addEventListener(type,fn,false); }else if(el.attachEvent){ el.attachEvent(‘on‘+type,fn); }else{ el[‘on‘+type] = fn; } } function alertIndex(){ alert(2); } addEvent(ipt[0],‘click‘,function(){ alert(1) }); addEvent(ipt[0],‘click‘,alertIndex);
时间: 2024-10-31 03:50:17