-1
我已經嘗試過locahost,它是好的,因爲我用ftp將文件複製到我的網站作爲我的任務,它不工作....是否有以下代碼的任何問題?JavaScript表單驗證不工作在網站上
這裏是我的XHTML代碼形式:
</p><form enctype="multipart/form-data" method="post" action="insert.php" onsubmit="return validateForm()" name="register" >
<table style="width: 300px;">
<tbody>
<tr>
<td>Username: * </td>
<td><input type="text" name="username" /></td> <<one of name forms
</tr>
<tr>
<td>Password: * </td>
<td><input type="text" name="password" /></td> <<name of forms
</tr>
<tr>
<td>Email: * </td>
<td><input type="text" name="email" /></td> <<name of forms
</tr>
<tr>
<td> * is must fulfilled </td>
</tr>
<tr>
<td><button value="Submit" type="submit">Submit</button></td>
<td><button value="Reset" type="reset">Clear</button></td></tr></tbody></table>
</form>
,這裏是我的javascript
function validateForm() {
var y = document.forms["register"]["username"].value;
if (y == null || y == "") {
alert("Username must be filled out");
return false;
}
var z = document.forms["register"]["password"].value;
if (z == null || z == "") {
alert("Password must be filled out");
return false;
}
var x = document.forms["register"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
alert("Not a valid e-mail address");
return false;
}
}
是JavaScript嵌入或從文件導入?如果它被導入,則可能是在將文件移動到服務器後路徑被破壞。 – dramzy 2014-10-12 04:21:16
「*不起作用*」究竟意味着什麼? – 2014-10-12 04:31:59
javascript是外部文件。它不工作意味着提交按鈕指向insert.php而不是首先驗證頁面 – 2014-10-12 04:46:34