button 按钮,结合onclick事件,验证和提交表单


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <style type="text/css"></style>
  <script type="text/javascript">
  //button 按钮,结合onclick事件,验证和提交表单
  function checkForm(){
        //判断用户名是否为空
        if(document.form1.username.value==""){
                window.alert("用户名不能为空");
        }else if(document.form1.username.value.length<5 || document.form1.username.value.length>20){
            window.alert("用户名长度必须介于5-50个字符之间!");
        }else{
            //使用form对象的submit()方法,实现提交。
            document.form1.submit();        
        }
  }
 </script>
 </head>
 <body>
  <form name="form1" method="get" action="login.php">
  用户名:<input type="text" name="username" />
  密码:<input type="password" name="userpwd" />
  <input type="button" value="提交表单" onclick="checkForm()" />
  </form>
 </body>
</html>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM