And*_*rew 6 html javascript jquery spring twitter-bootstrap
我的目标是使用bootstrap验证器验证具有类名或Id的字段
这是示例代码:
HTML:
<input id="myFirstId" class="myClass" type="text" name="myFirstName" />
<input id="mySecondId" class="myClass" type="text" name="myLastName" />
Run Code Online (Sandbox Code Playgroud)
JS:
$('#myForm').bootstrapValidator({
fields : {
myFirstName : {
validators : {
notEmpty : {
message : 'required'
}
}
},
myLastName : {
validators : {
notEmpty : {
message : 'required'
}
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
但我想要一个块来使用bootstrap验证器验证这两个元素
恩.
$('#myForm').bootstrapValidator({
fields : {
myClass : { // <-- this is not working but i want to validate those
// object with has 'myClass' class.
validators : {
notEmpty : {
message : 'required'
}
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
请参见http://bootstrapvalidator.com/settings/#field-selector
您可以使用selector而不是名称来使用类名:
$('#myForm').bootstrapValidator({
fields: {
myClass: {
selector: '.myClass',
validators: {
notEmpty: {
message: 'required'
}
}
},
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5264 次 |
| 最近记录: |