I have a question,是关于preventDefault的
<a href="https://www.baidu.com" id="goto">跳转</a> <script> var event={ // 增添事件 addEvent:function(ele,type,handle){ if(ele.addEventListener){ ele.addEventListener(type,handle,false); }else if(ele.addElement){ ele.addElement("on"+type,handle); }else{ ele["on"+type] = handle; } }, //阻止默认行为 preventDefault:function(event){ if(event.preventDefault){ event.preventDefault(); }else{ event.returnValue=false; } } }; var goto=document.getElementById("goto"); event.addEvent(goto,"click",function(e){ e=event || window.event; event.preventDefault(e); }); </script>
如上,可是在浏览器中无论chrome还是IE都无效啊,该跳转还是跳转了.