【问题标题】:jQuery: Remove error after autocomplete happens in a fieldjQuery:在字段中发生自动完成后删除错误
【发布时间】:2018-03-07 20:04:43
【问题描述】:

我在页面上唯一的输入文本字段中使用Daterangepicker 代替Bootstrap。当我将输入文本字段留空时,会出现错误,这就是我想要的。但是,当我使用Daterangepicker 填写输入文本字段时,错误仍然存​​在。

我希望将其删除。单击“开始”按钮时,错误文本会自行删除,但我希望在输入字段中填充文本后,错误文本会自行删除。

这是我的代码:

$('#beginBtn').on('click', function() {     
  //Validation of Open Enrollment input
  var autocd = $('#autocd').val();
  if(autocd == "") {
    $('#autocderror').text('Cannot be blank').css({'color': 'red'});
    return false;
  } else if (autocd != "") {
    $('#autocderror').fadeOut(1000);
  }

  var startDate = $("input[name='daterangepicker_start']").val();
  var endDate = $("input[name='daterangepicker_end']").val();

  //console.log(startDate + " thru " + endDate);

  $.post('api/countdownprocess.php', {startDate:startDate, endDate:endDate}, function(data) {
    if(data == 'Successful'){
      $('#oerestext').html(data).css({'color': 'green'}).fadeOut(3000);
      setTimeout(function() {
        location.reload();
      }, 5000);
    } else {
      $('#oerestext').html(data).css({'color': 'red'}).fadeOut(3000);
    }
  });// end of Begin Button

输入字段称为autocd。我怎么做?有没有办法让自动完成作为选择器?

【问题讨论】:

    标签: javascript jquery twitter-bootstrap validation daterangepicker


    【解决方案1】:

    如何将这段代码移动到由输入上的 onchange 事件触发的函数中?

    var autocd = $('#autocd').val();
    if(autocd == "") {
      $('#autocderror').text('Cannot be blank').css({'color': 'red'});
      return false;
    } else if (autocd != "") {
      $('#autocderror').fadeOut(1000);
    }
    

    【讨论】:

    猜你喜欢
    • 2013-01-08
    • 1970-01-01
    • 2011-02-03
    • 2015-10-07
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多