如果输入的电子邮件无效,我有一个发布错误消息的表单。我希望将错误消息文本更改为红色。我怎么能这样做?
$('#subscribe-form').bootstrapValidator({
live: 'disabled',
fields: {
email: {
validators: {
emailAddress: {
message: 'Please enter a valid email address'
}
}
},
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form role="form" id="subscribe-form">
<div class="form-group">
<input type="email" class="form-control custom-email" name="email" id="email" placeholder="Email Address">
</div>
<button type="submit" class="btn btn-large custom-button">Sign up !</button>
</form>
答案 0 :(得分:2)
只需在代码中添加以下css
即可.has-error .help-block {
color: red;
}
$('#subscribe-form').bootstrapValidator({
live: 'disabled',
fields: {
email: {
validators: {
emailAddress: {
message: 'Please enter a valid email address'
}
}
},
}
});
&#13;
.has-error .help-block {
color: red;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<form role="form" id="subscribe-form">
<div class="form-group">
<input type="email" class="form-control custom-email" name="email" id="email" placeholder="Email Address">
</div>
<button type="submit" class="btn btn-large custom-button">Sign up !</button>
</form>
&#13;
答案 1 :(得分:1)
如果正确添加了Bootstrap,您应该已将错误文本设置为红色。如果没有,这将解决这个问题。
small.help-block {
color: #F44336 !important;
}
$('#subscribe-form').bootstrapValidator({
live: 'disabled',
fields: {
email: {
validators: {
emailAddress: {
message: 'Please enter a valid email address'
}
}
},
}
});
small.help-block {
color: #F44336 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.5.3/js/bootstrapValidator.js"></script>
<form role="form" id="subscribe-form">
<div class="form-group">
<input type="email" class="form-control custom-email" name="email" id="email" placeholder="Email Address">
</div>
<button type="submit" class="btn btn-large custom-button"> Sign up ! </button>
</form>