私はJavascriptを学んでいるだけなので、私の質問がばかげているように思われる場合は、我慢してください...
htmlフォームを作成し、フィールドで検証を実行する必要があります。フィールドが正しく入力されているかどうかに関係なく、送信ボタンを押すとエラー404が発生します。同じことをする他の人のコードをコピーして貼り付けると、正常に機能します。ファイル「somepage.php」は存在しませんが、他の人のコードには存在しません。
私はそれをCodeLobsterでコーディングし、次にNotepad++でコーディングしました。変化なし。
これがHTMLファイルで、さらに下にjavascriptファイルの内容があります...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Registration Form</title>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<form action="somepage.php" onsubmit="checkLogin()" method="post" >
Name: <input type="text" name="name" id="nameF" /><br />
Email: <input type="text" name="email" id="emailF" /><br />
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
function checkLogin()
{
var emailPattern = /^\w+([\.\-]?\w+)*@\w+([\.\-]?\w+)*\.[a-z]{2,6}$/i;
var email = document.getElementById('emailF').value;
var name = document.getElementById('name').value;
if (email == "")
{
alert("Please enter valid email address.");
document.getElementById('emailF').select();
document.getElementById('emailF').focus();
return false;
} else if (name == "") {
alert("Please enter your name.");
document.getElementById('nameF').select();
document.getElementById('nameF').focus();
return false;
} else if (!emailPattern.test(email)) {
alert("The email address entered is invalid");
document.getElementById('emailF').select();
document.getElementById('emailF').focus();
return false;
}
return true;
}