【问题标题】:JQuery - Removing validation for a single text boxJQuery - 删除单个文本框的验证
【发布时间】:2015-01-06 22:44:11
【问题描述】:

我有一组已使用 JQuery 对其进行验证的文本框。 我们正在验证任何“文本”类型的输入以使用该函数:

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">

请建议任何方法来解决和删除仅针对此文本框的必填字段验证。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-3 validation


    【解决方案1】:

    包括.not 选择器的输入:

    $('#modalEditBody input:text').not('.multiselect-search, #removefield_validation')
        .each(function() {
            ...
        });
    

    【讨论】:

      【解决方案2】:

      #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;
                  }
              });

      【讨论】:

        猜你喜欢
        • 2012-03-30
        • 2014-05-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-07
        • 1970-01-01
        • 2013-12-15
        相关资源
        最近更新 更多