这是我的代码:
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/js/validation/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="/js/validation/jquery.validationEngine.js"></script>
<script type='text/javascript'>
$( document ).ready(function() {
$(".register_form").validationEngine();
$(".register_form").bind("jqv.field.result", function(event, field, errorFound, prompText){
console.log(errorFound) ;
});
});
</script>
<form id="contact-form" action ="<?php echo $this->basePath()."/user/register" ?>" method ="post" name="register_form" class="register_form">
<div class ="col-md-6">
<div class="text-fields">
<div class="float-input">
<input name="username" id="username" type="text" class ="validate[required,custom[onlyLetterNumber],maxSize[20]] text-input" placeholder="username" >
<span><i class="fa fa-user"></i></span>
</div>
</div>
</div>
<button type="submit" name="contact-submit" id="register_submit">
<i class="fa fa-user"></i>
Register
</button>
</form>
如您所见,我只有一个输入文本字段(用户名)。但是当我在控制台中加载页面时,我收到以下错误消息: **
TypeError: $(...).validationEngine is not a function
$(".register_form").validationEngine();
**
为什么?我已经检查了stackoverflow中的多个帖子,这些帖子有相关的问题,但是没有它们正在为我工作
答案 0 :(得分:1)
<script type="text/javascript" src="/js/validation/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="/js/validation/jquery.validationEngine.js"></script>
我相信你不应该在开头有那些领先的斜线:
<script type="text/javascript" src="js/validation/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="js/validation/jquery.validationEngine.js"></script>
因此路径错误且未加载库。然后调用尚未定义的函数/方法。
答案 1 :(得分:0)
经过研究,我发现此错误仅在验证单选按钮或复选框时出现,如下所示:
<input id="level1" class="validate[required] radio" name="level" value="1" type="radio">
<input id="level2" class="validate[required] radio" name="level" value="2" type="radio">
<input id="level3" class="validate[required] radio" name="level" value="3" type="radio">
删除该内容或更正这些内容以继续。