【发布时间】:2021-11-24 00:57:25
【问题描述】:
我想在页面开始时“隐藏”表格,该表格正在使用$(document).ready(function(){$("#result").hide();});
但是我也想在单击提交按钮后“显示”表格,这是行不通的。
这是 PHP 文件,因为之后我必须添加更多 PHP 代码。如果我将其更改为 HTML,结果相同。
<!DOCTYPE html>
<html lang ="en">
<head>
<title> Show Specific </title>
<meta charset = "utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous">
</script>
<script>
$(document).ready(function(){
$("#result").hide();
});
$(document).ready(function(){
$("#button").click(function(){
$("#result").show();//result
});
});
</script>
</head>
<body>
<hr>
<div id="appointment">
<form>
Test ID: <input type="text" name="testID" /> <br><br>
First Name : <input type="text" name="First_Name" /> <br><br>
Last Name : <input type="text" name="Last_Name" /> <br><br>
<input id="submit" type="button" value="Submit" ><br><br>
</form>
</div>
<div id="result">
<table>
<tr>
<th>Test ID</th>
</tr>
<tr>
<th>First Name </th>
</tr>
<tr>
<th>Last Name</th>
</tr>
</table>
</div>
<hr>
<div id="footer">
<footer> Copyright © ALL RIGHTS ARE RESERVED. </footer>
</div>
</body>
</html>
【问题讨论】:
-
因为您的提交正在进行页面导航,在这种情况下页面会重新加载。 CSS 更改不会通过页面导航保留。如果您希望某些更改持续存在,则必须将某种状态信息保存到
localStorage之类的位置,并在页面加载时重做该更改
标签: javascript php jquery refresh show-hide