原因:
<button></button>
如果不设置type属性, 除了 IE 中 默认 type = “button”, 其他浏览器默认 type = “submit” 。点击便会提交表单,刷新页面。
解决办法:
-
将
<button></button>
改为<input type="button">
或者直接在<button>
中添加属性 type=“button”。 -
阻止默认事件, 在button点击事件中加入“e.preventDefult()”
$('btn').click(function(e){
e.preventDefult();
});
参考链接:
https://www.w3school.com.cn/tags/tag_button.asp.
https://www.cnblogs.com/smlp/p/9676174.html.