Ich arbeite an einem kleinen Projekt, und nach einer langen Dokumentation ohne Ergebnis habe ich beschlossen, etwas Hilfe zu bitten. Woran ich gerade arbeite, ist ein Allokations-Barcode-System in PHP und Jquery. Der Zuweisungsvorgang, wie Sie im Code sehen, umfasst vier Scans, zuerst scannen, um die Zuweisungssitzung zu öffnen, zweitens, um die Bestellung zu scannen, drittens, um das Standortregister zu scannen und viertens, um das Bestätigungsfenster durch erneutes Scannen der Bestellung zu erhalten der Fehler ist). Der letzte Scan sollte alle Eingabefelder des Formulars verwischen, bevor das Bestätigungsfenster geöffnet wird. Dies funktioniert eine Weile, aber dann fängt der Code an, den Fokus auf das zuletzt ausgewählte Eingabefeld zu halten und die Zahlen damit zu vermischen.JQuery versucht, den Fokus aus den Texteingabefeldern durch einen Scan zu entfernen
Dies ist die Scanner-Erfassungsfunktion der vier Schritte als Callback-Funktion, die durch Scan-Scan zu folgen.
(es ist in einer document.ready Funktion gewickelt ist, ich einfach nicht den gesamten Code kopieren)$(document).scannerDetection({
timeBeforeScanTest: 200, // wait for the next character for upto 200ms
startChar: [120], // Prefix character for the cabled scanner (OPL6845R)
endChar: [13], // be sure the scan is complete if key 13 (enter) is
detected
avgTimeByChar: 40, // it's not a barcode if a character takes longer than
40ms
onComplete: function(barcode, qty){
// main callback function
console.log(barcode);
order=barcode;
if($("*:contains('ADD YOUR ORDER')").length>0){
count++;
if(count==1){
console.log('First step');
$("#allocation #ordNum").focus();
var lineOrd=$("#allocation #ordNum").closest("tr");
$(lineOrd).addClass("focus");
}
if(count==2){
console.log('Second Step');
if($("#allocation #ordNum").val()) {
var matchItem=/^\d+$/;
ord=$("#allocation #ordNum").val();
if(matchItem.test(ord)===false){
alert("Give a valid order number!");
window.location.href=window.location.href;
}
$(".focus").removeClass("focus");
$.post("ajax.inc.php",
{action:"scanN",order:ord}).done(function(data){
dataa=$(data).text();
if(dataa.indexOf("1.)")>=0){
document.getElementById("soundEffect").play();
alerting=true;
alert(dataa);
}
});
console.log("there is something: "+ord);
$("#allocation #location").focus();
var lineLoc=$("#allocation #location").closest("tr");
$(lineLoc).addClass("focus");
}else{
alert('Give a valid ordernumber.');
count--;
}
}
if(count==3){
console.log('Third step');
if($("#allocation #location").val()){
loc=$("#allocation #location").val();
$(":text").blur(); //the line what stops working
console.log('location has value');
$("#allocation #update").focus();
//var matchItem2=/^\s?[A-B]\s?[1-6]\s?[A-E]\s?[1-6]\s?$/;
var matchItem2=/^\s?[A-B]\s?[1-6]\s?[A-E]\s?[1-6]\s*$/;
if(matchItem2.test(loc)===false){
alert("Give a valid location!");
window.location.href=window.location.href;
}
}
}
if(count==4){
console.log('Forth step');
$(".focus").removeClass("focus");
if(barcode===ord){
var confi=confirm('Order '+ord+' added to location '+loc);
if(confi==true){
$.post("ajax.inc.php",
{action:"scan",order:ord,location:loc,thestat:thestat})
.done(function(data){
console.log('Order added');
$(".container").append(data);
setTimeout(function(){
window.location.href=window.location.href;
},500);
//window.location.href=window.location.href;
console.log('confirmed');
});
}
if(confi==false){
window.location.href=window.location.href;
console.log('not confirmed');
}
}else{
alert('Allocation is confirmed by rescan of the order');
count--;
}
}
}
if($("h2.scan:contains('SCAN TO SEARCH ORDER')").length>0){
$(".container #locations").remove();
$(".container h4#process").remove();
console.log('Scanning Picknote');
$.post("ajax.inc.php{action:"scanN",order:order}).done(function(data)
{
$(".container").append(data);
});
}
if($("h2.scan:contains('SCAN TO PROCESS ORDER')").length>0){
console.log('Delete order');
console.log('order:'+order);
$.post("ajax.inc.php,
{action:"delete",order:order}).done(function(data){
$(".container #processed").append(data);
$(".container #locations .forProcess
span#"+order).slideUp();
});
}
}
});
Jede Hilfe kann hilfreich sein. Was ich erreichen möchte, ist, sobald der Scan auf Nummer 3 ist, aus jedem Eingabefeld auf dem Formular zu fokussieren. Selbst wenn es erreicht wurde, hat es aus irgendeinem Grund nach einer Weile aufgehört. Danke.
Dank Colin für die Ankündigung, das war kopieren und einfügen Fehler, ist das Koma dort. Ich denke, dass es wegen des Alarmfensters das Problem sein könnte. Alles bis zum Zeitpunkt, an dem das Benachrichtigungsfenster seine Rolle hat. – domjanzsoo
Das ist ein sehr guter Punkt. Eine Warnung wird den Fokus auf die Schaltflächen in der Eingabeaufforderung bringen. Vielleicht nach der Warnung setzen Sie den Fokus zurück auf die Eingabe mit. Fokus()? – Colin