pwdCheck(str){ 
var reg=/^[a-zA-Z0-9]{6,16}$/; 
if(reg.test(str)==true) 
      return true; 
      else{ 
document.getElementById("str2").innerText="    密码格式不正确!"; 


这个函数前边 没有写 function 

解决方案 »

  1.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head> 
        <base href=" <%=basePath%>"> 
        
        <title>My JSP 'index.jsp' starting page </title> 
    <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"> 
    <!-- 
    <link rel="stylesheet" type="text/css" href="styles.css"> 
    --> 
    <script type="text/javascript"> 
    function isEmail(str){ 
          var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/; 
          if(reg.test(str)==true) 
          return true; 
    else{ 
    document.getElementById("str1").innerText="    邮箱地址格式不正确!"; 

    } function hide1(){ 
    document.getElementById("str1").innerText=""; 

      
    function pwdCheck(str){ //----------------------------function....
    var reg=/^[a-zA-Z0-9]{6,16}$/; 
    if(reg.test(str)==true) 
          return true; 
          else{ 
    document.getElementById("str2").innerText="    密码格式不正确!"; 

    } function hide2(){ 
    document.getElementById("str2").innerText=""; 

    </script> 
      </head> 
      
      <body> 
        <form> 
        <table> 
        <tr height="100pt"> 
        <td>邮箱地址: </td> 
        <td> <input type="text" id="eml" onblur="isEmail(this.value)" onfocus="hide1()"/> </td> 
        <td> <div id="str1"> 
        </div> </td> 
        </tr> 
        <tr height="50pt"> 
        <td>密码: </td> 
        <td> <input type="password" id="pwd1" onblur="pwdCheck(this.value)" onfocus="hide2()"/> </td> 
        <td> <div id="str2"> 
        </div> </td> 
        </tr> 
        <tr height="50pt"> 
        <td> <strong> <em>密码由数字和英文字母组成,长度在6-16位之间 </em> </strong> </td> 
        </tr> 
        <tr> 
        <td>确认密码: </td> 
        <td> <input type="password" id="pwd2" onblur=""/> </td> 
        </tr> 
        </table> 
        </form> 
      </body> 
    </html> 
      

  2.   

    晕,竟然犯了这么低级的错误,谢谢了,还想问下,每个提示框我都得定义一个hide函数用来使其获得焦点时错误提示消失,这样未免太麻烦,能不能对所有提示框都只定义一个hide函数来实现这个功能?
      

  3.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head> 
        <base href=" <%=basePath%>"> 
        
        <title>My JSP 'index.jsp' starting page </title> 
    <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"> 
    <!-- 
    <link rel="stylesheet" type="text/css" href="styles.css"> 
    --> 
    <script type="text/javascript"> 
    function isEmail(str){ 
          var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/; 
          if(reg.test(str)==true) 
          return true; 
    else{ 
    document.getElementById("str1").innerText="    邮箱地址格式不正确!"; 


    /*
      
       加个参数变量就可以了,onfocus事件直接传参
      
    */
    function hide(sId){ 
    document.getElementById(sId).innerText=""; 

      
    function pwdCheck(str){ //----------------------------function....
    var reg=/^[a-zA-Z0-9]{6,16}$/; 
    if(reg.test(str)==true) 
          return true; 
          else{ 
    document.getElementById("str2").innerText="    密码格式不正确!"; 


    </script> 
      </head> 
      
      <body> 
        <form> 
        <table> 
        <tr height="100pt"> 
        <td>邮箱地址: </td> 
        <td> <input type="text" id="eml" onblur="isEmail(this.value)" onfocus="hide('str1')"/> </td> 
        <td> <div id="str1"> 
        </div> </td> 
        </tr> 
        <tr height="50pt"> 
        <td>密码: </td> 
        <td> <input type="password" id="pwd1" onblur="pwdCheck(this.value)" onfocus="hide('str2')"/> </td> 
        <td> <div id="str2"> 
        </div> </td> 
        </tr> 
        <tr height="50pt"> 
        <td> <strong> <em>密码由数字和英文字母组成,长度在6-16位之间 </em> </strong> </td> 
        </tr> 
        <tr> 
        <td>确认密码: </td> 
        <td> <input type="password" id="pwd2" onblur=""/> </td> 
        </tr> 
        </table> 
        </form> 
      </body> 
    </html>