How can I check if a value is changed on blur event?

前端 未结 10 1215
时光说笑
时光说笑 2021-02-07 06:29

Basically I need to check if the value is changed in a textbox on the \'blur\' event so that if the value is not changed, I want to cancel the blur event.

If it possible

10条回答
  •  死守一世寂寞
    2021-02-07 06:46

    Using Jquery events we can do this logic

    Step1 : Declare a variable to compare the value

    var  lastVal ="";
    

    Step 2: On focus get the last value from form input

      $("#validation-form :input").focus(function () {
                     lastVal = $(this).val();
    
      });
    

    Step3:On blur compare it

    $("#validation-form :input").blur(function () {
                     if (lastVal != $(this).val())
                     alert("changed");
                 });
    

提交回复
热议问题