JavaScprit刷新8种方法

测试: chrome,火狐浏览器,360浏览器,IE9

测试说明:火狐浏览器,IE9点击《刷新》,input的内容都不会清空

<html>
<body>
<input type="button" value="1" onclick="refresh1()">
<input type="button" value="2" onclick="refresh2()">
<input type="button" value="3" onclick="refresh3()">
<input type="button" value="4" onclick="refresh4()">
<input type="button" value="5" onclick="refresh5()">
<input type="button" value="6" onclick="refresh6()">
<input type="button" value="7" onclick="refresh7()">
<input type="button" value="8" onclick="refresh8()">
<br><br>
<input type="text">
</body>
<html>

<script type="text/javascript">
function refresh1(){
  history.go(0);
  //ie9无效
  //火狐有刷新效果,但input内容不刷新
}

function refresh2(){
  location.reload();
  //火狐有刷新效果,但input内容不刷新
}

function refresh3(){
  location = location;
}

function refresh4(){
  location.assign(location);

}

function refresh5(){
  document.execCommand('Refresh')
  //ie9无效
  //chrome无效
  //火狐无效
  //360无效
}

function refresh6(){
  window.navigate(location);
  //chrome无效
  //火狐无效
  //360无效
}

function refresh7(){
  location.replace(location); 

}

function refresh8(){
  document.URL = location.href;
  //chrome无效
  //360无效
  //火狐无效
}

</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值