<span class="glyphicon glyphicon-calendar"></span>
我花了几个小时研究,但似乎没有人接受这个奇怪的问题。有谁知道为什么? 非常需要帮助!以下是我的问题和我当前代码的截图
$(document).ready(function () {
$.validator.setDefaults({
highlight: function (element, errorClass, validClass) {
if (element.type === "radio") {
this.findByName(element.name).addClass(errorClass).removeClass(validClass);
} else {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error has-feedback');
$(element).closest('.form-group').find('span.glyphicon').remove();
$(element).closest('.form-group').append('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
}
},
unhighlight: function (element, errorClass, validClass) {
if (element.type === "radio") {
this.findByName(element.name).removeClass(errorClass).addClass(validClass);
} else {
$(element).closest('.form-group').removeClass('has-error has-feedback').addClass('has-success has-feedback');
$(element).closest('.form-group').find('span.glyphicon').remove();
$(element).closest('.form-group').append('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
}
}
});
$('#dataForm').validate({
rules: {
startDateInput: {
required: true
}
},
submitHandler: function (form) {
alert('success');
}
});
});
<form id="dataForm" method="post" action="#">
<div class="form-group">
<label class="control-label col-md-4" for="startDateInput">Start Date</label>
<div class="input-group date" id="startDateInput" style="max-width: 280px" data-provide="datepicker">
<input type="text" class="form-control" name="startDateInput">
<div class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</div>
</div>
<input type="submit" class="btn btn-primary" value="Save" id="saveButton" />
</div>
</form>
答案 0 :(得分:0)
正如@Rich在评论中所提到的,以下行删除了图标。
$(element).closest('.form-group').find('span.glyphicon').remove();