[size=10px]JSP代码一部分:<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>  <head>
  <script language="javascript" src="<%=path %>/js/Nametest.js" charset="utf-8"></script>
  </head>
  
  <body>
  
    <form action="<%=path%>/ExamineServlet.do" method="post">
    <center><h3> 注册系统</h3><p>
    用户名:<input name="username" type="text" id="Reusername" onblur="nametest()"><br>
    <div id="name_blank">请填写用户名</div><p>
    <div id="name_blank2">用户名中存在非法字符,请重新填写!(只能是英文、下划线和数字的组合,不能超过12个字符)</div><p>
......Nametest.js里面的函数:function nametest()
{
 var     i,strlengh,tempchar;   
 var     str=document.getElementById("Reusername").value;   
         if(str==""||str==null)   
         document.getElementById("name_blank").style="disply:block"; 
         else 
         document.getElementById("name_blank").sstyle="display:none";
         strlength=str.length;   
         for(i=0;i<strlength;i++)   
         {   
                   tempchar=str.substring(i,i+1);   
                   if(strlength>16||!(tempchar=='0'||tempchar=='1'||tempchar=='2'||tempchar=='3'||tempchar=='4'||tempchar=='5'||tempchar=='6'||tempchar=='7'||tempchar=='8'||tempchar=='9'||
                   tempchar=='_'||tempchar=='a'||tempchar=='A'||tempchar=='b'||tempchar=='B'||tempchar=='c'||tempchar=='C'||tempchar=='d'||tempchar=='D'||tempchar=='e'||
                   tempchar=='E'||tempchar=='f'||tempchar=='F'||tempchar=='g'||tempchar=='G'||tempchar=='h'||tempchar=='H'||tempchar=='i'||tempchar=='I'||tempchar=='j'||
                   tempchar=='J'||tempchar=='k'||tempchar=='K'||tempchar=='l'||tempchar=='L'||tempchar=='m'||tempchar=='M'||tempchar=='n'||tempchar=='N'||tempchar=='o'||
                   tempchar=='O'||tempchar=='p'||tempchar=='P'||tempchar=='q'||tempchar=='Q'||tempchar=='r'||tempchar=='R'||tempchar=='s'||tempchar=='S'||tempchar=='t'||
                   tempchar=='T'||tempchar=='u'||tempchar=='U'||tempchar=='v'||tempchar=='V'||tempchar=='w'||tempchar=='W'||tempchar=='x'||tempchar=='X'||tempchar=='y'||
                   tempchar=='Y'||tempchar=='z'))                    
                   {
                   document.getElementById("name_blank2").style="display:block";     
                   break;
                   }
                   else
                   document.getElementById("name_blank2").style="display:none";                       
         }      
}应该是失去焦点就会检测的,不管为空还是输入字符不合法都应该显示DIV标签的字出来,但是我运行啥效果都没,哪儿错了???
[/size]

解决方案 »

  1.   

    呃。。怎么说呢,还是用正则表达式去匹配吧,这么一大串的看这都累,你写的不累???还有一个地方明显有错误document.getElementById("name_blank").sstyle="display:none";
      

  2.   

    js出错用IE的开发人员工具或者FF的FireBug
      

  3.   

    myeclipse具体怎么调试啊,我看师兄操作了一遍,但是我在DEBUG视图不知道怎么做才能找到哪儿有错.