您好,阅读了上一篇文章中建议进行的更改,但我看不到 JS 工作,我没有错误,有人可以告诉我哪里出错了吗?谢谢
当用户没有输入足够的字符或太多的字符时,此示例场景会更改文本的颜色。我还想知道是否可以将文本框的颜色也更改为红色。
<script type="text/javascript">
function checkForm()
{
var username = document.getElementsById('username').value;
if(username.length<5)
{
alert("Username is to short");
return false;
}
else if (username.lenght<16)
{
alert("Username is to long");
return false;
}
else
{
return true;
}
}
function checkUsername()
{
var username = document.getElementsById('username').value;
var element = document.getElementsById('username1');
if(username.lenght<5)
{
element.innerHTML = "Username is to short";
element.style.color = "red";
}
else if (username.lenght>16)
{
element.innerHTML = "Username is to long";
element.style.color = "red";
}
else
{
element.innerHTML = "Valid Username";
element.style.color = "green";
}
}
</script>
<p><b><h3>Welcome User Please Register</h3></b></p>
<form action="registerUserProcess.php" id="registerUserForm" method="post" name="registerUserForm" onSubmit='return checkForm();'>
<table>
<tr><td><label id="username1">Username</label></td><td><input id="username" type="text" size="16" onBlur='checkUsername();'/></td></tr>