edd*_*ark 4 javascript jquery plugins jquery-plugins twitter-bootstrap-3
这是我第一次使用这个插件.我正在使用jQuery v-1.10.我也在使用migrate插件.我添加了js文件.我已经使用prepros添加了所有这些.但是插件仍然不能正常工作.
控制台中也没有显示错误; 只有警告显示:
不推荐使用event.returnValue.请改用标准的event.preventDefault().
我的表单和JS代码如下.
<form id="login-form" method="post" action="#" novalidate>
<label for="login-email" class="control-label">Email : </label>
<input id="login-email" class="form-control" name="email" type="email" placeholder="Email..." required><br>
<label for="login-password" class="control-label">Password : </label>
<input id="login-password" class="form-control" name="password" type="password" placeholder="Password..." required><br>
<input class="btn btn-default" name="submit" type="submit" value="Submit">
</form>
$("#login-form input").not("[type=submit]").jqBootstrapValidation();
Run Code Online (Sandbox Code Playgroud)
小智 7
您必须在标记中使用适当的控件才能使其正常工作.
防爆.
<form ...>
<div class="control-group">
<label ...>Email</label>
<div class="controls">
<input ... />
<p class="help-block"></p>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我个人认为处理javascript的更好方法是创建一个"验证"类,因为并非所有字段都需要验证.但我认为这实际上取决于你的表单元素:你可能确实要求整个表单被验证,但在我使用的大多数表单中,只有某些元素需要验证,因此创建一个类来调用你的javascript更好这样jqBootstrapValidation.js就不会扫描整个表单.
防爆.
/* assigned by class */
$(function(){$(".validated").jqBootstrapValidation();});
/* assigned by element */
$(function(){$("input,select,textarea").not("[type=submit]").jqBootstrapValidation();});
Run Code Online (Sandbox Code Playgroud)
然后,只需将"已验证"类添加到需要验证的任何内容中:
<input type="email" class="form-control validated" name="email" id="email" placeholder="Email Address" required />
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
4020 次 |
| 最近记录: |