首页 > 技术文章 > 如何阻止button默认的刷新页面操作

LYL-8 2018-09-21 09:50 原文

当button在form表单时,点击button会自动触发button的默认事件,也就是刷新当前页面。那么如何阻止呢:

有两种方式:

一:将<button></button>改为<input type="button">  或者直接在<button>中添加属性 type="button".

二:在button的点击事件中

$('btn').click(function(e){

e.preventDefult();

.......

.......

});

 

阻止冒泡

function sss(event){

event.stopPropagation();

}

推荐阅读