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

前端 未结 10 1214
时光说笑
时光说笑 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:36

    You can use this code:

    var Old_Val;
    var Input_Field = $('#input');
    
    Input_Field.focus(function(){
         Old_Val = Input_Field.val();
    });
    
    Input_Field.blur(function(){
        var new_input_val = Input_Field.val();
        if (new_input_val != Old_Val){
              // execute you code here
        }
    });
    

提交回复
热议问题