尝试将jQuery验证引擎用于1个文本字段。出于某种原因,它没有做任何事情。我没有任何错误可以解决。如果有人看到丢失或不合适的东西,我会很感激。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src='jquery-1.11.0.min.js'></script>
<script src="jQuery-Validation-Engine-master/js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="jQuery-Validation-Engine-master/js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="jQuery-Validation-Engine-master/css/validationEngine.jquery.css" type="text/css"/>
</head>
<body>
<form id="formID" name="myForm" method="post" action="submit.action">
<input class="validate[required]" type="text" id="agree" name="agree"/>
<button type="button" value="Save" id="Save" onclick="clicked();">Submit Survey</button>
</form>
<script type="text/javascript">
function clicked() {
if (confirm('Are you sure you want to submit?')) {
$("#form.id").validationEngine();
} else {
return false;
}
}
</script>
</body>
</html>`
答案 0 :(得分:4)
你应该像这样初始化validationEngine而不是onclick函数:
$(document).ready(function(){
$("#formID").validationEngine();
});
答案 1 :(得分:3)
您的选择器错误
变化:
$("#form.id").validationEngine();
$("#form.id")
- &gt;引用标识为form
且类id
为:
$("#formID").validationEngine();