刷新页面后,jQuery 功能在 PHP 中不起作用
jQuery function is not working in PHP once the page is refreshed
我想在页面开始时“隐藏”table,它正在使用 $(document).ready(function(){$("#result").hide();});
但我也想在单击提交按钮后“显示”table,这是行不通的。
这是 PHP 文件,因为之后我必须添加更多 PHP 代码。如果我将其更改为 HTML thou.
,结果相同
<!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>
如果你仔细看,你的输入按钮的 id
是 submit
而不是你在 jQuery 事件处理程序上写的 button
。
将您的脚本更改为这个:
<script>
$(document).ready(function(){
$("#result").hide();
$("#submit").click(function(){
$("#result").show();//result
});
});
</script>
另外:你没有必要有两个$(document).ready()
方法。只实现一个,然后在里面添加你的功能。
我想在页面开始时“隐藏”table,它正在使用 $(document).ready(function(){$("#result").hide();});
但我也想在单击提交按钮后“显示”table,这是行不通的。
这是 PHP 文件,因为之后我必须添加更多 PHP 代码。如果我将其更改为 HTML thou.
,结果相同<!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>
如果你仔细看,你的输入按钮的 id
是 submit
而不是你在 jQuery 事件处理程序上写的 button
。
将您的脚本更改为这个:
<script>
$(document).ready(function(){
$("#result").hide();
$("#submit").click(function(){
$("#result").show();//result
});
});
</script>
另外:你没有必要有两个$(document).ready()
方法。只实现一个,然后在里面添加你的功能。