我正在使用 Bootstrap 3 框架和 jQuery 验证插件通过直接在每个表单字段的右侧显示“绿色勾号”图像来显示表单字段上的错误 - 它只是在字段下方显示图像而不是显示到正确的。
我正在尝试在此演示 http://alittlecode.com/files/jQuery-Validate-Demo/index.html上模拟以下表单
<div class="col-xs-10">
<div class="form-group">
<label for="inputFirstName" style="display: none;">First Name</label>
<?= form_input('first_name', '', "id='first_name' class='form-control {$error}'"); ?>
</div>
<div class="form-group">
<label for="inputLastName" style="display: none;">Last Name</label>
<?= form_input('last_name', '', "id='last_name' class='form-control {$error}'"); ?>
</div>
</div>
我的 CSS/JS 如下:
<script type="text/javascript" src="/assets/js/includes/jquery.validate.min.js"</script>
<script type="text/javascript">
$(document).ready(function () {
$('#checkout-form').validate({
rules: {
first_name: {
minlength: 2,
required: true
},
email: {
required: true,
email: true
}
},
highlight: function (element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function (element) {
element.text('OK!').addClass('valid')
.closest('.control-group').removeClass('error').addClass('success');
}
});
});
</script>
<style type="text/css">
label.valid {
width: 16px;
height: 16px;
background: url('/assets/images/icons/tick.png') center center no-repeat;
display: inline-block;
text-indent: -9999px;
}
label.error {
font-weight: bold;
color: red;
padding: 2px 8px;
margin-top: 2px;
}