用span实现表单验证,但是没有达到预期效果
我写的验证用户输入的怎么没有反映啊?当输入3个字的时候有个提示出来错误,结果没有提示,不知道这么写是不是正确
(我不想用alert方法,就是我怎么写,帮我改下好吗)
<html>
<head>
<title> login </title>
<style type= "text/css ">
span.validateError
{
color: red;
visibility: hidden;
}
</style>
</head>
<body>
<script language= "javascript " >
<!--
function chek()
{
if (document.myform.username.value.length==3)
{
document.getElementById( "nameError ").style.visibility = "visible ";
}
else
document.getElementById( "nameError ").style.visibility = "hidden ";
}
-->
</script>
<form name = myform method = post action = Result.jsp>
<div align = center> <span class=style1> <h3> login </h3> </span> </div>
<table align = center border = 0>
<hr>
<tr>
<td> Name </td>
<td>
<input type = text name = username onkeyup= "chek() " >
<span id= "nameError " class= "validateError ">
</span>
</td>
</tr>