我正在使用this。
所以主要的问题是如果我清除缓存CTRl+F5
我的自定义验证功能不再起作用,如果我在清除缓存后点击F5一切正常。
最初我认为这是关于在html中加载库的顺序,因为我已经在jquery和html之后请求的另一个源文件中进行了jquery和自定义验证defer
。但是我已经删除了延迟,因为无论如何我都遇到了$ - unknown function
错误,但是在清除缓存之后代码仍无效
其他问题(由于缺乏文档)是:
data-error
的自定义错误,则不会显示自定义错误我要在下面预览
$("document").ready(function(){
$("form").validator(
{
custom :{
result: function($el) {
if ($el.val().trim() != 10) {
return "Worng answer from validator"
}
}
},
errors:{
//this never works
'result':"Wrong answer from errors"
}
}
);
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.9/validator.js"></script>
<form data-toggle="validator" role="form" id="formValidator" class="col-sm-4">
<div class="form-group has-feedback">
<label for="inputCaptcha" class="control-label">5 + 5 = this has error from html</label>
<input type="text" data-result="Wrong answer from html" data-result-error="Wrong from html" class="form-control" id="inputCaptcha" placeholder="Answer here" required>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<div class="help-block with-errors"></div>
</div>
<!-- ******************************** -->
<div class="form-group has-feedback">
<label for="inputCaptcha" class="control-label">5 + 5 = this has error from validator</label>
<input type="text" data-result data-result-error class="form-control" id="inputCaptcha" placeholder="Answer here" required>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
尝试查看整页并使用清除缓存进行测试