嘿傢伙真的基本問題在這裏我遇到了麻煩。這是我第一次從頭開始編碼驗證,無法弄清楚爲什麼他們不工作。當我點擊我的提交按鈕時,它只是轉發到「您的文件未找到」頁面。它根本不承認我的驗證者。通常在驗證器上輸入,以及如何改進或修復此問題將不勝感激。簡單的驗證器不工作,新的自定義驗證程序
<DOCTYPE!>
<html>
<head>
<script src="gen_validatorv4.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div id= "videoGameCircuit">
<img src="Images/vg.jpg" width="900" height="400" alt="video game circuit" />
</div>
<div>
<form action="myForm" onsubmit="return validateForm()" method="post">
Name: <input type="text" name="name" value="" size="25" maxlength="50" /><br>
Email: <input type="text" name="email" value="" size="25" maxlength="50" /><br>
<input type="submit" name="submit" value="sign me up!" />
</form>
<script type="text/javascript">
var frmvalidator = new Validator("myForm");
//where myform is the name/id of your form
var ele = myForm; ele.addEventListener("submit", function(e){e.preventDefault();
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please enter your name");
frmvalidator.addValidation("name","maxlen=20", \t "Max length for name is 20");
frmvalidator.addValidation("name","alpha_s","Name can contain alphabetic chars only");
</script>
</div>
</body>
</head>
</html>
http://stackoverflow.com/questions/27918843/javascript-validate-form-before-submit .. http://stackoverflow.com/questions/27918843/javascript-validate-form-before-submit –
仔細看看那裏。您有表單提交問題。您需要添加一個偵聽器來阻止默認提交。然後你可以運行你的驗證和東西,並在以後提交,如果一切都會好的。這裏是偵聽器的例子http://stackoverflow.com/questions/7410063/how-can-i-listen-to-the-form-submit-event-in-javascript ..也validateForm()方法?你有嗎? –
@MykolaBorysyuk仍然是一個問題。 –