• 表单元素提交时JS判断输入的值为空时则不刷新页面返回,不为空跳转并传值到新页面


     <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();"> -----重点return +函数名实现为空返回原界面------------
                               <div  id="username">
                                      <div id="content">
                                           <input type="text" name="user" id="user"  class="bgc" autofocus="autofocus" placeholder="您的姓名" />
                                           <div><img src="images/word3.svg" /></div>
                                      </div>
                               </div> 
                             <input type="submit" id="sub" value="提交"></div>
                             </form>
              </div>
       
       </body>
          <script type="text/javascript">
     function submitCheck(){
                var txt = document.getElementById("user");
                if(txt.value==""){
                alert("请输入您的姓名");
                txt.focus();
                return false;   
               }
                return true;
      }
          </script>
    <?php 
          $username=$_GET['user']; -------接收传过来的值
         
    ?>
    
    
     <div id="link"><?php echo $username ?></div>-----输出传过来的值
  • 相关阅读:
    zju 2886
    zju 2478
    UVA350-水题
    UVA699-落叶-二叉树
    UVA327
    UVA548
    java环境变量
    synchronized关键字
    uva297
    UVA196
  • 原文地址:https://www.cnblogs.com/kangshuai/p/5000827.html
Copyright © 2020-2023  润新知