【发布时间】:2016-06-28 12:50:37
【问题描述】:
问题:如何在继续使用 jqBootstrapValidation 作为验证器的同时加快验证速度?
问题: 我有一个小的联系表单设置,使用 jqBootstrapValidation 作为验证器非常好,但是当我开始添加其他字段时,它变得非常慢,以至于如果我在表单字段中键入多个字符,验证器需要一秒钟以上的时间来响应。
使用 20-30 个表单字段可以很容易地观察到减速。
我试过了:
到目前为止,我已经尝试了很多方法,例如使用 style="display: none;" 隐藏元素,但这似乎对速度没有影响。
我可以在提交之前对表单进行部分处理,但我没有太多运气。有没有更好的方法来解决这种情况,也许我缺少一些简单的东西,因为我对 JavaScript 比较陌生?
我当前的表单/js:在我们添加更多表单字段之前效果很好。
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Title</title>
</head>
<body id="page-top" class="index">
<form name="sentMessage" id="contactForm" novalidate>
<div class="control-group">
<label>Name</label>
<input type="text" placeholder="Name" id="name" required data-validation-required-message="Please a name.">
<p class="help-block text-danger"></p>
</div>
<div class="control-group">
<label>Message</label>
<textarea rows="3" placeholder="Message" id="message" required data-validation-required-message="Enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
<br>
<div id="success"></div>
<div>
<button type="submit">Click to send</button>
</div>
</form>
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Contact Form Script -->
<script src="js/jqBootstrapValidation.js"></script>
<script>
$(function() {
$("#contactForm input,#contactForm textarea").jqBootstrapValidation();
});
</script>
</body>
</html>
使用的验证器: http://ReactiveRaven.github.com/jqBootstrapValidation/
【问题讨论】:
-
注意:我确实使用引导程序来管理我的布局,这就是使用 jqBootstrapValidation 的原因。出于这个问题的目的,我已经删除了所有与引导相关的代码,以便更容易接近。
标签: javascript jquery jqbootstrapvalidation