数据表单未重置

时间:2018-06-27 05:48:42

标签: javascript jquery html

用于保存数据和重置数据的书面代码。在这种情况下,数据保存成功,但无法重置表单。当我单击铅笔图标时,它会变成软盘并删除图标。如果我单击软盘上的数据将被保存,但是当我单击删除图标数据表将不会被重置。我这样尝试过代码

val gd = GradientDrawable()
        gd.shape = GradientDrawable.RECTANGLE
        gd.setColor(Color.RED)
        gd.cornerRadius = 15.0f
        mBinding.actMainTextview.setBackground(gd)

        mBinding.actMainTextview.setOnClickListener(object : View.OnClickListener {
            override fun onClick(v: View?) {
                gd.setColor(Color.YELLOW)
            }

        })
//Banking details form validation
$(document).ready(function() {
  $('.editBankDetailBtn').click(function() {
    if ($('.editBankDetail').is('[readonly]')) { //checks if it is already on readonly mode
      $('.editBankDetail').prop('readonly', false); //turns the readonly off
      $('.editBankDetailBtn').html(
        '<span class="glyphicon glyphicon-floppy-disk">&nbsp;</span>' +
        '<span id="reset-form" class="glyphicon glyphicon-remove">&nbsp;</span>');
      //  $('.glyphicon-remove')[0].reset();

    } else { //else we do other things

      var patt = /^([0-9]{11})|([0-9]{2}-[0-9]{3}-[0-9]{6})$/;
      var reg = /^[A-Za-z]{4}[0-9]{6,7}$/;
      patt.test('acdbdfdsfsf22-333-666666'); // true

      var bname_1 = document.getElementById('name').value;

      if (bname_1 == "") {

        document.getElementById('name').style.borderColor = "red";
        return false;
      } else {
        document.getElementById('name').style.borderColor = "#cccccc";
      }

      $('.editBankDetail').prop('readonly', true);
      $('.editBankDetailBtn').html(
        '<span class="glyphicon glyphicon-pencil">&nbsp;</span>');
      $('.glyphicon-remove').on('click', function() {
        $("#reset-form").trigger("reset");
      });
    }
  });
});

2 个答案:

答案 0 :(得分:1)

您有几件事

  • 您需要重置表单,而不是像现在一样重置图标
  • 请在bankName上有一个toggleClass-它不是name,而是代码中的bankName
  • 您需要委派-像这样-获取事件处理程序的元素必须在页面中是静态的,并且在委派时就存在,这里$('.editBankDetailBtn')

$('.editBankDetailBtn').on('click', '.glyphicon-remove', function() {
  $("#myForm")[0].reset()
});

答案 1 :(得分:0)

您的点击将不适用于动态创建的点击。添加以下代码

$(document).on('click', '.glyphicon-remove', function() {
  // Put one alert or console to check that you here
    $("#YOU_FORM_ID")[0].reset(); //
});