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>輸出
這將產生以下輸出 −
單擊 “重新載入” 按鈕之前 −

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

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP