0
我正在處理一個小項目,並且在沒有結果的長文檔之後,我決定尋求一些幫助。 我正在做的是在php和jquery中分配基於條碼的系統。 您將在代碼中看到的分配過程包括四個掃描,第一次掃描以打開分配會話,第二次掃描訂單,第三個掃描位置貨架,第四個通過重新掃描訂單獲取確認窗口(步驟該錯誤是)。 最後一次掃描應該在打開確認窗口之前模糊窗體的所有輸入字段。這會工作一段時間,但隨後代碼開始將注意力集中在最後選擇的輸入字段上,通過這個數字搞亂了數字。JQuery試圖通過掃描將焦點從文本輸入字段中刪除
這是具有掃描儀檢測功能回調函數的四個步驟,以遵循安全掃描(它被包裹在一個的document.ready功能,我只是沒有複製整個代碼)
$(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();
});
}
}
});
任何幫助都可能有幫助。我想實現的目標是,一旦掃描次數達到第3次,就會將注意力集中在表單上的每個輸入字段中。即使達到目的,出於某種原因,它會在一段時間後停止執行。 謝謝。
感謝科林的通知,這是複製粘貼錯誤,昏迷是存在的。我在想這可能是由於警報窗口造成的問題。直到警報窗口具有角色爲止。 – domjanzsoo
這是一個很好的觀點。警報將把焦點帶到提示中的按鈕。也許警告後,使用.focus()將焦點設置回輸入? – Colin