HTML DOM Location reload() 方法


HTML DOM Location reload() 方法用於重新渲染當前文件。它提供與瀏覽器中的“重新載入”按鈕相同的功能。

語法

語法如下 −

location.reload(forceGetParameter)

引數

此處,“forceGetParameter” 可以是以下內容 −

forceGetParameter詳細資訊
true它定義從伺服器重新載入當前文件。
false它定義從瀏覽器快取重新載入當前文件。

示例

讓我們看一個 Location reload() 屬性的示例 −

 即時演示

<!DOCTYPE html>
<html>
<head>
<title>Location reload()</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
   text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Location-reload( )</legend>
<label for="urlSelect">Email: </label>
<input type="email" id="emailSelect"><br>
<label for="urlSelect">Password: </label>
<input type="password" id="passSelect"><br>
<input type="button" onclick="doReload()" value="Reload">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var emailSelect = document.getElementById("emailSelect");
   var passSelect = document.getElementById("passSelect");
   divDisplay.textContent = 'Do not reload, all the details will be lost';
   function doReload(){
      alert('Page reloaded, all the details are lost');
      location.reload();
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

單擊 “重新載入” 按鈕之前 −

填寫詳細資訊後單擊 “重新載入” 按鈕 −

更新於: 30-Jul-2019

222 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始吧
廣告
© . All rights reserved.