jq获取焦点事件

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'login.jsp' starting pagetitle>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    
<script type="text/javascript" src="/wangxuewei1510C20170728/js/jquery-1.11.0.js">script>
<script type="text/javascript">
    $(function() {
        //页面加载完成
        $("#daoruId").click(function() {
            location.href="/wangxuewei1510C20170728/servlet/DaoruServlet";
        });

        var flag1 = false;
        var flag2 = false;

        $("#nameId").blur(function() {
            var $name  = $("#nameId").val();
            var $nameSpan = $("#nameSpan");
            if($name.trim() == ""){
                $nameSpan.html("不能为空");
            }else{
                $nameSpan.html("");
                flag1 = true;
            }
        });

        $("#pwdId").blur(function() {
            var $pwd = $("#pwdId").val();
            var $pwdSpan = $("#pwdSpan");
            if($pwd.length < 6){
                $pwdSpan.html("不能小于6位");
            }else{
                $pwdSpan.html("");
                flag2 = true;
            }
        });


        $("#loginId").click(function() {
            if(flag1 && flag2){
                var url = "/wangxuewei1510C20170728/servlet/SelectServlet";
                var params = {
                    "name":$("#nameId").val(),
                    "pwd":$("#pwdId").val(),
                };
                $.post(url,params,function(data){
                    if(data == 1){
                        alert("登录成功");
                        location.href = "/wangxuewei1510C20170728/servlet/FindAllServlet";
                    }else{
                        alert("不正确");
                    }

                },"json");  

            }

        });



    });


script>
head>
  <body>
    用户名<input type="text" id="nameId"/><span id="nameSpan" style="color: red">span><br>
    密 码<input type="password" id="pwdId"/><span id="pwdSpan" style="color: red">span><br>
    <input type="button" value="登录" id="loginId"/>
    <input type="button" value="导入数据" id="daoruId"/>
  body>
html>

你可能感兴趣的:(jq获取焦点事件)