我创建了一个登录页面,其中包含一个登录表单,该表单将用户名和密码提交给 loginproc.php,以检查它们的有效性并且一切正常。无论如何,在登录页面上,我编写了一个 JavaScript 函数,在用户名和密码字段为空的情况下提醒用户。完成后,JavaScript 工作正常,但是当我单击提交按钮时,绝对没有任何反应!
----------------------------------------这是JavaScript------ ----------------
<script type='text/javascript'>
function formValidator(){
// Make quick references to our fields
var username = document.getElementById('username');
var password = document.getElementById('password');
// Check each input in the order that it appears in the form!
if(notEmpty(username, "The username field is empty!")){
if(notEmpty(password, "The password is empty!")){
}
}
return false;
}
function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
</script>
----------------------------------------这是表格------ ----------------
<form method="post" action="loginproc.php" onsubmit="return formValidator()" >
<tr><td colspan="3"><img src="icons/login.jpg" alt="Edugate" width="366" height="123"></td></tr>
<tr><td colspan="3" nowrap bgcolor="#990033" class="infoTitle"><div align="center"></div></td></tr>
<tr><td colspan="3" nowrap class="infoTitle"><div align="left">user login </div></td></tr>
<tr><td colspan="3" nowrap bgcolor="#990033" class="infoTitle"><div align="center"></div></td></tr>
<tr><td width="58">Username</td>
<td width="4">:</td>
<td width="297"><input type="text" id="username" name="username" size="20"></td></tr>
<tr><td>Password</td><td>:</td><td><input type="password" id="password" name="password" size="20"></td></tr>
<tr><td> </td><td> </td><td><input type="submit" class="BtnInTable" value="Login"></td></tr>
<?php if ($error == 1)
print "<tr><td colspan='3' class='ppos'><img src='icons/error.png' alt='error'> Icorrect usename or password...</td></tr>";?>
<tr><td colspan="3" nowrap bgcolor="#990033" class="infoTitle"><div align="center"></div></td></tr>
</form>
拜托,谁能指导我。提前感谢