在 jQuery 中清除所有表单字段后刷新页面?
jqueryweb developmentobject oriented programming更新于 2025/8/21 18:37:17
要刷新页面,请使用 JavaScript 中的 location.reload()。示例 JavaScript 代码如下。 −
示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<body>
<form>
<label for="userId">
UserName:
<input type="text" >
</label>
<br>
<label for="pass">
Password:
<input type="password" >
</label>
<br>
<button type="submit" id="RefreshPage" >Refresh Page</button>
</form>
<script>
$('#RefreshPage').click(function() {
location.reload();
});
</script>
</body>
</html>
要运行上述程序,请将文件名保存为"anyName.html(index.html)",然后右键单击该文件。在 VS Code 编辑器中选择"使用实时服务器打开"选项。
输出
将产生以下输出 −

填写表单后,快照如下 −

点击"刷新页面"按钮后,页面将刷新,并显示以下输出 −


