js提交表单

核心: document.getElementById("formid").submit(); 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆界面</title>
    <link rel="stylesheet" href="index.css">
    <style>
        *{
        margin: 0;
        padding: 0;
        list-style: none;
        }
        body{
            width:100%;
            background-image: url('img/bg.jpg');
            background-size: cover;
        }
        .main{
           width:40%;
           margin-left:30%;
           margin-right:30%;
           margin-top:200px;
        }
        .header{
           margin-top:100px;
           height:100px;
           text-align:center;
           font-size:60px;
           font-family: 华文新魏;
           color: #dacc3e;
        }
        .headline{
            font-size: 22px;
            text-align: center;
            color:  #fffefd;
        }
        input[type="text"],
        input[type="password"],
        input[type="button"]{
            -web-kit-appearance:none;
            -moz-appearance: none;
            display: block;
            margin: 0 auto;
            font-size:15px;
            width: 35%;
        }
        input[type="text"],
        input[type="password"]{
            height:36px;
            border-radius:18px;
            border:1px solid #c8cccf;
            color:#6a6f77;
            outline:0;
        }
        input[type="button"]{
            margin-top: 25px;
            height: 35px;
            background: #357eb8;
            color: #bcedff;
            font-weight: bold;
            font-size: 16px;
            border-radius:18px;
        }
        input[type="button"]:hover{
            background: #0e62a3;
            cursor: pointer;
        }
        .astyle{
            margin-left:35%;
            margin-right:35%;
            font-size:17px;
            color: #6a6f77;
       }
       .astyle{
            color:#fff5d3;
            margin-top: 20px;
       }
       .isLogin{
       text-align: center;
       color: red;
       }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">红星医院后台管理系统</div>
        <!-- 主体内容 (登陆界面)--><div class="main">
                    <form:form id="formid" action="adminlogin" modelAttribute="admin" method="post">
                        <p class="headline"><strong>超级管理员登陆</strong></p>
                        <p class="astyle">用户账号:</p>
                        <form:input type="text" id="id" placeholder="请输入账号" path="id" />
                        <p class="astyle">密码:</p>
                        <form:input type="password" id="adminpassword" placeholder="请输入密码" path="adminpassword" />
                        <input type="button" value="登陆" name="login" onclick="adminsubmit();"><br>
                        <c:if test="${loginflag}">
                        <p class="isLogin">密码或账号错误</p>
                        </c:if>
                    </form:form>
        </div>
        
    </div>
   <script type="text/javascript">
    function adminsubmit()
    {
        //获取用户账号
        var account=document.getElementById("id").value;
        //alert(account);
        //获取用户密码
        var password=document.getElementById("adminpassword").value;
        //提交标志
        var flag=true;
        //正则表达式
    	var reg=new RegExp("^([1-9][0-9]*)$");
        //验证账户不为空
        if(account.toString()=="")
        {
            alert(100);
            flag=false;
            alert("对不起!账号不能为空");
        }else
        {   //验证不为0开头并且不含有其他字符
        	if(!reg.test(account)){
        		flag=false;
                alert("对不起! 账号起始不能为0");
           }else{
        	   //验证密码不能为空
               if(password=="")
               {
                   flag=false;
                   alert("对不起!密码不能为空,并且不含有其他非数字字符");
               }
        	
           }
        }

        //判断是否提交
        if(flag==true)
        {
            document.getElementById("formid").submit();
        }

    }
</script>
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值