schrieb ich eine Funktion addMoney(), die durch einen Klick in Eingabefeld eingeben Anrufe:Javascript keypress in keypress
$('body').on('keypress', 'input[type=text]', function(e){
if(e.keyCode==13){
var val = $('input[type=text]').val();
switch(val) {
case '-help':
SeeComands();
break
case '-copyright':
SeeAuthors();
AddNewLine();
break
case '-addmoney':
addMoney();
break
default:
SaveCommand();
Animal('I see nothing here, try smthing else',function(){AddNewLine();})
}
}
Diese Funktion erzeugt ein neues Eingabefeld ein, in dem beginnt die Feststellung eines regulären Ausdrucks eingeben, klicken in String, der über letzte Eingabe übergeben wurde:
function addMoney() {
SaveCommand();
Animal('E', function(){//интсрукция ко вводу Enter the number of banknotes introduced through the gap
Animal('U',function(){ //Use a template <count of banknotes>x<nominal of banknotes>
AddNewLine();
$('body').on('keypress', 'input[type=text]', function(e){//Checking the input string
if(e.keyCode==13){
var vali = $('input[type=text]').last().val();
console.log('val: ', vali);
SaveCommand();
var reg100 = /([1-9]{1,})(?=x100)/g; //RegExp to find the amount of the nominal value of 100 bills
var reg200 = /([1-9]{1,})(?=x200)/g; //RegExp to find the amount of the nominal value of 200 bills
var reg500 = /([1-9]{1,})(?=x500)/g; //RegExp to find the amount of the nominal value of 500 bills
var reg1000 = /([1-9]{1,})(?=x1000)/g; //RegExp to find the amount of the nominal value of 1000 bills
var reg5000 = /([1-9]{1,})(?=x5000)/g; //RegExp to find the amount of the nominal value of 5000 bills
var result100 = vali.match(reg100);
var result200 = vali.match(reg200);
var result500 = vali.match(reg500);
var result1000 = vali.match(reg1000);
var result5000 = vali.match(reg5000);
console.log('100:', result100, '200:', result200, '500:', result500, '1000:', result1000);
};
});
});
});
};
Aber Bremse des Schalters arbeitet früher, bis AddMoney() arbeitet. Als Ergebnis vali erklärte:
var vali = $('input[type=text]').last().val();
nicht definiert ist und als Ergebnis habe ich nicht ein Ergebnis von addMoney(), aber ein Standard-Schalter Ergebnis haben: Animation „Ich sehe nichts hier, versuchen smthing else“ I denke, es ist wegen Funktion Animal() kann b:
function Animal(string, callback) {
var a = ''; //The variable which will be entered character by character string
var i= 0;//Counter of a letters
var p = document.createElement('p');
$('body').append(p);
Anima();
function Anima() {//Animation Function
a=a+string[i];
i++;
$('p').last().text(a);
var timer = setTimeout(Anima, 100);
if(i==string.length){
clearTimeout(timer);
callback();//For running in order
};
};
};
... aufgrund Funktion Anima(), die als Rekursion durch SetTimeOut läuft()