使用jQuery验证插件验证引导表单时是否需要使用名称属性? [英] Do I need to use name attributes when validating a bootstrap form with jQuery Validation plugin?
本文介绍了使用jQuery验证插件验证引导表单时是否需要使用名称属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
>< label for =emailclass =label>电子邮件地址< / label>
< input name =emailtype =textid =email>
但通过引导程序,通常不会使用名称attr。
< div class =form-group>
< label for =inputPasswordclass =col-lg-2 control-label>密码< / label>
< div class =col-lg-5>
< input type =passwordclass =form-controlid =inputPassword-placeholder =Password>
< / div>
< / div>
我想我只是混淆了jquery验证器从哪里获取信息。电子邮件是否提及attr名称或标签?
规则:{
电子邮件:{
required:true,
email:true
},
解决方案 验证器使用
名称
属性来查找字段,因为所有表单元素必须具有名称属性。 您发布的第二块HTML代码无效。
Still kind of new and I just started using bootstrap but basically when using stock HTML I see name attributes being used like so
<label for="email" class="label">E-mail Address</label>
<input name="email" type="text" id="email">
but with bootstrap there is typically no name attr used.
<div class="form-group">
<label for="inputPassword" class="col-lg-2 control-label">Password</label>
<div class="col-lg-5">
<input type="password" class="form-control" id="inputPassword-" placeholder="Password">
</div>
</div>
I guess i'm just confused where the jquery validator is pulling information from. Does the email refer to the name attr or the label for?
rules: {
email: {
required: true,
email: true
},
解决方案
The validator uses the name
attribute to find the field, as all form elements must have a name attribute.
The second block of HTML code you've posted is not valid for that reason.
这篇关于使用jQuery验证插件验证引导表单时是否需要使用名称属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文