阻止默认行为

默认行为

不需要写js代码也能执行的一些行为,如:a标签点击就能跳转、form提交、鼠标右击 ....
 

阻止默认行为

阻止a标签\form标签也是3种办法
 1.将a标签的href改了
 2.在a标签的点击事件的最后,加上 return false
 3.利用事件对象
document.querySelector("a").onclick = function(e){
     var e = e || window.event;
     // 阻止默认行为
      e.preventDefault()
//     // 在低版本ie中
//     // e.returnValue = false
//     console.log("呵呵");


    //return false;
}

 

 
posted @ 2021-01-12 15:45  技术活当赏  阅读(119)  评论(0)    收藏  举报