HTML表单调用JS方法无效果!
逍遥随风翼 2010-11-01 07:28:12 [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]