zoukankan      html  css  js  c++  java
  • js 验证用户名和密码是否为空

        <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
          
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
          
        <html>  
          
          <head>  
          
            <title>My JSP 'userValidate.jsp' starting page</title>  
              
             <script type="text/javascript">  
                function checkUserName(obj){  
                    var username = obj;  
                    var checkUserNameResult = document.getElementById("checkUserNameResult");    
                    if(username.trim().length==0){  
                          checkUserNameResult.innerHTML = "用户名不能为空";    
                          obj.focus();  
                    }else{  
                         checkUserNameResult.innerHTML = "";    
                    }  
                }  
            </script>  
          
            <script type="text/javascript">  
                function checkPassword(obj){  
                    var password = obj;  
                    var checkPasswordResult = document.getElementById("checkPasswordResult");   
                    if(password.trim().length==0){  
                        checkPasswordResult.innerHTML = "密码不能为空";    
                        obj.focus();  
                    }else{  
                         checkPasswordResult.innerHTML = "";    
                    }  
                }  
          
            </script>  
          
          </head>  
          
          <body>  
          
            
          
          <table>  
              <tr>  
                <td>用户名:</td>  
                <td><input type="text" name="username"  onblur="checkUserName(this.value);" /></td>  
                <td><span id="checkUserNameResult" style="color: red "></span>  </td>  
            </tr>  
          
            <tr>  
          
            <td>密  码:</td>  
            <td><input type="password" name="password" onblur="checkPassword(this.value);"/>  
            <td><span id="checkPasswordResult" style="color: red "></span></td>  
           
            </tr>  
          
            <tr><td><input type="submit" value="提交" ></td></tr>  
          
            </table>  
          
          
          </body>  
          
        </html> 

  • 相关阅读:
    .net中的正则表达式使用高级技巧 (二)
    经典的LZW算法C语言实现
    .net中的正则表达式使用高级技巧
    Atlas应用程序调试技巧
    从毕业到现在是如何走来的!!!
    关于JS的一些实际问题
    js学习笔记(十四)事件处理模型
    js学习笔记(十一)窗口和框架
    关于css的一些问题
    浏览器布局BUG汇总
  • 原文地址:https://www.cnblogs.com/FLWL/p/6049286.html
Copyright © 2011-2022 走看看