我想接受用户输入,并在每次更改输入时更新此输入。发生这种情况时,“ main”方法应运行一段代码,并将userChange和updateCalc重置为false。

    //For Example
    updateCalc=false;
    userChange= false;


    $(function(){

      $("#inputUsers").change(function(){  // user input that can be called at anytime
    userChange = true;
    inputUsers = $(this).val();
    updateCalc = true;
    });

    if(updateCalc == true){  //"main" method that is called whenever updatecalc is true

    alert(1);
updateCalc = false;
userChange = false;
    }




    });

最佳答案

您的思维方式错误。您可以做,但方法不同。希望对您有所帮助

updateCalc=false;
userChange= false;

checker_func = function() {
  $("#inputUsers").change(function(){  // user input that can be called at anytime
     userChange = true;
     inputUsers = $(this).val();
     updateCalc = true;
  });

  if(updateCalc == true){
    alert(1);
    updateCalc = false;
    userChange = false;
  }
}

setInterval("checker_func();",1000); // checks your codes every 1000 milisecond

09-20 04:45