我对 js 完全陌生,我为@大学的一个项目制作了这个表格,但 js 似乎根本不起作用。我没有收到任何错误,它只是不起作用!我启用了 Javascript,并且完全禁用了无脚本。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['css'];?>"/>
<script type="text/javascript">
function validate_f() {
var result=true;
var username=document.getElemenetById('username').value;
var illegalChars = /\W/;
var x=document.getElemenetById('email').value;
var pwd=document.getElemenetById('password').value;
if (illegalChars.test(username) || username.length>25) {
result=false;
alert("Username must be latin chars and not more than 25 characters");
}
if (x==null || x=="" || username == null || username=="" || pwd == null || pwd == "" || afm == null || afm == "" ) {
result=false;
alert("you have to fill up all the Boxes dude");
}
return result;
}
<div id="main">
<div id="formcontainer">
<form id="data" name="data" action="connection.php" method="POST" on submit="return validate_f()">
<table width="100%" cellpadding="3" cellspacing="2">
<tr>
<td width="25%"> </td>
</tr>
<tr>
<td class="right" width="20%"> <strong> Username </strong> </td>
<td>
<input type="text" name="username" id="username" size="25" maxlength="25"/>
</td>
</tr>
<tr>
<td class="right"> <strong> Password</strong> </td>
<td>
<input type="password" name="password" id="password" size="25" maxlength="25"/>
</td>
</tr>
<tr>
<td class="right"> <strong> Email</strong> </td>
<td>
<input type="text" name="email" id="email"/>
</td>
</tr>
<?php
/*
<tr>
<td class="right"> <strong> Security Code: </strong> </td>
<td>
<img src="CaptchaSecurityImages.php" alt="" />
<input id="security_code" name="security_code" type="text" />
</td>
</tr>
*/
?>
<tr>
<td>
<input name="reset" type="reset" id="reset" value="Reset" />
<input name="submit" type="submit" id="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
</div>
</div>