我有一组文本框,使用JQuery进行验证。 我们正在验证任何类型为“text”的输入以使用该函数:
eventValidation.validate = function () {
var success = true;
$('#modalEditBody input:text').not('.multiselect-search').each(function () {
if ($(this).val().length > 1) {
$(this).parent().find('.glyphicon-exclamation-sign').removeClass('show').addClass('hidden');
$(this).parent().removeClass('has-error');
} else {
$(this).parent().find('.glyphicon-pencil').addClass('hidden');
$(this).parent().find('.glyphicon-exclamation-sign').removeClass('hidden').addClass('show');
$(this).parent().addClass('has-error');
success = false;
}
});
我只需要为单个文本控件删除此必需的字段验证。
<input id="removefield_validation" class="" type="text" value="some_value">
请为此文本框建议解决和删除必填字段验证的任何方法。
答案 0 :(得分:1)
将#removefield_validation
添加到.not选择器中,如下所示:
eventValidation.validate = function () {
var success = true;
$('#modalEditBody input:text').not('.multiselect-search, #removefield_validation').each(function () {
if ($(this).val().length > 1) {
$(this).parent().find('.glyphicon-exclamation-sign').removeClass('show').addClass('hidden');
$(this).parent().removeClass('has-error');
} else {
$(this).parent().find('.glyphicon-pencil').addClass('hidden');
$(this).parent().find('.glyphicon-exclamation-sign').removeClass('hidden').addClass('show');
$(this).parent().addClass('has-error');
success = false;
}
});
&#13;
答案 1 :(得分:1)
将输入包含在.not
选择器中:
$('#modalEditBody input:text').not('.multiselect-search, #removefield_validation')
.each(function() {
...
});