Can jQuery check whether input content has changed?

前端 未结 9 1055
轮回少年
轮回少年 2020-12-23 19:30

Is it possible to bind javascript (jQuery is best) event to \"change\" form input value somehow?

I know about .change() method, but it does not trigger

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 19:52

    I had to use this kind of code for a scanner that pasted stuff into the field

    $(document).ready(function() {
      var tId,oldVal;
      $("#fieldId").focus(function() {
         oldVal = $("#fieldId").val();
         tId=setInterval(function() { 
          var newVal = $("#fieldId").val(); 
          if (oldVal!=newVal) oldVal=newVal;
          someaction() },100);
      });
      $("#fieldId").blur(function(){ clearInterval(tId)});
    });
    

    Not tested...

提交回复
热议问题