为什么点击button会自动刷新页面

本文探讨了在HTML中使用button标签时遇到的表单提交问题,并提供了多种解决方案,包括更改button类型、使用JavaScript阻止默认行为,以及实现页面刷新的方法。同时,文章列举了多种使用input标签实现页面刷新的代码示例。

因为button标签按钮会提交表单。

解决方法如下:

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

2、在button的点击事件中加入“e.preventDefult()” 

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

e.preventDefault();

});

点击button刷新的几种常用代码:

1、<input type=button value=刷新 onclick="history.go(0)">

2、<input type=button value=刷新 onclick="location.reload()">

3、<input type=button value=刷新 onclick="location=location">

4、<input type=button value=刷新 onclick="location.assign(location)">

5、<input type=button value=刷新 onclick="document.execcommand(refresh)">

6、<input type=button value=刷新 onclick="window.navigate(location)">

7、<input type=button value=刷新 onclick="location.replace(location)">

8、<input type=button value=刷新 onclick="window.open(自身的文件,_self)">

9、<input type=button value=刷新 onclick=document.all.webbrowser.execwb(22,1)>

评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值