<body> <div id="Div1"style="Display:block;"> <div id="logo"></div> <div id="word1"></div> <div id="Word2"></div> <form name="Form1"Method="Get"action="zhengshu.php"onsubmit="return Submitcheck ();">-----Key return + function name implemented as NULL returns the original interface------------<div id="username"> <div id="content"> <input type="text"Name="User"Id="User" class="BGC"autofocus="Autofocus"Placeholder="Your name"/> <div>"Images/word3.svg"/></div> </div> </div> <input type="Submit"Id="Sub"Value="Submit"></div> </form> </div> </body> <script type="Text/javascript">function Submitcheck () {vartxt = document.getElementById ("User"); if(txt.value=="") {alert ("Please enter your name"); Txt.focus (); return false; } return true; } </script>
<? php $username=$_get['user'];------- receive the value passed ?> <div id="link"><?php echo $username?></div> the value-----output.
When the form element is submitted, JS determines that the input value is empty, does not refresh the page return, does not jump to the null and passes the value to the new page