我想接受一个用户输入,并在每次更改此输入时更新此输入。发生这种情况时,"main"方法应该运行一个代码块并将用户更改和更新计算回 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