以下是我们cs.aspx
召回页面的代码。我们的想法是,我们扫描一个条形码并引用代码来查看UPC在召回列表中的位置。如果是,则应该显示“STOP SIGN”,如果它不在列表中,则应该显示“GREEN Light”。以下代码的问题在于,在调用“绿灯”图标后,需要在键盘上手动输入以便下一次条形码扫描才能正常工作。
以下是结果:
我迷路了。以下是代码(我们使用Chrome或Firefox浏览器调用cs.aspx
)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>
<!DOCTYPE html>
<html lang="en">
<head id="Head1">
<meta charset="utf-8" />
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function () {
$('#txtUPC').focus();
$("input").keyup(function (event) {
var strUPC = $(this).val();
if (strUPC == "000035" ) {
$("#stop_dialog").show();
var lblStopText = "Recalled Product: UPC:000035 Product: Test Scan";
$('#lblStop').val(lblStopText);
$("#check_green").hide();
setTimeout(function () {
$("input").prop('disabled', true);}, 800);
return;
}
if (strUPC == "037600245289" ) {
$("#stop_dialog").show();
var lblStopText = "Recalled Product: UPC:037600245289 Product: Hormel Chili Hot No Beans";
$('#lblStop').val(lblStopText);
$("#check_green").hide();
setTimeout(function () {
$("input").prop('disabled', true);}, 800);
return;
}
if (strUPC == "013409128442" ) {
$("#stop_dialog").show();
var lblStopText = "Recalled Product: UPC:013409128442 Product: Sweet Baby Ray's Baffolo Wing Sauce";
$('#lblStop').val(lblStopText);
$("#check_green").hide();
setTimeout(function () {
$("input").prop('disabled', true);}, 800);
return;
}
if (strUPC == "041130311222" ) {
$("#stop_dialog").show();
var lblStopText = "Recalled Product: UPC:041130311222 Product: Shoppers Value Pinto Beans";
$('#lblStop').val(lblStopText);
$("#check_green").hide();
setTimeout(function () {
$("input").prop('disabled', true);}, 800);
return;
}
if (strUPC == "041800501267" ) {
$("#stop_dialog").show();
var lblStopText = "Recalled Product: UPC:041800501267 Product: Welch's Grape";
$('#lblStop').val(lblStopText);
$("#check_green").hide();
setTimeout(function () {
$("input").prop('disabled', true);}, 800);
return;
}
if (strUPC == "041130311208" ) {
$("#stop_dialog").show();
var lblStopText = "Recalled Product: UPC:041130311208 Product: Shoppers Value Dark Red Kidney Beans";
$('#lblStop').val(lblStopText);
$("#check_green").hide();
setTimeout(function () {
$("input").prop('disabled', true);}, 800);
return;
}
$("#check_green").toggle();
enterUPC(strUPC);
$('#txtUPC').focus();
$('#Reset').click();
});
$('#Reset').click(function () {
setTimeout(function () {
document.getElementById('txtUPC').focus();
}, 800);
setTimeout(function () {
document.getElementById('txtUPC').value = "";
}, 800);
});
function doreset() {
$('#txtUPC').val("");
$('#txtUPC').focus();
}
function enterUPC(strUPC) {
$('#lblUPC').val(strUPC);
var dNow = new Date();
var localdate = (dNow.getMonth() + 1) + '/' + dNow.getDate() + '/' + dNow.getFullYear() + ' ' + dNow.getHours() + ':' + dNow.getMinutes() + ':' + dNow.getSeconds();
$('#lbltimestamp').val(localdate);
setTimeout(function () {
$('#Go').click();
}, 200);
}
$('#Go').click(function () {
var code = {};
code.UPC = $("[id*=lblUPC]").val();
code.strDate = $("[id*=lbltimestamp]").val();
$.ajax({
type: "POST",
url: "CS.aspx/SaveUPC",
data: '{code: ' + JSON.stringify(code) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
});
return false;
});
});
</script>
</head>
<body>
Enter UPC: <input type="text" ID="txtUPC"/>
<br /> <input type="text" id="lblUPC" runat="server" readonly="readonly" style="border: 0px; background-color: transparent;" size="100" />
<br />
<input type="text" id="lbltimestamp" runat="server" readonly="readonly" style="border: 0px; background-color: transparent;" size="100" />
<input type="button" id="Go" value=""/>
<input type="button" id="Reset" value="Reset"/>
<br />
<div id="check_green" style="display: none">
<br /> <img src="Green.png" alt="Good" />
<br />
</div>
<div id="stop_dialog" style="display: none">
<input type="text" id="lblStop" runat="server" readonly="readonly" style="border: 0px; background-color: transparent;" size="100" />
<br />
<img src="Stop.png" alt="Stop" />
</div>
<form id="form1" runat="server">
<br />
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/json2/0.1/json2.js"></script>
</body>
</html>
(我不确定我在做什么)
答案 0 :(得分:1)
此行不正确:
$("#check_green").toggle();
每按一次键,它就会被切换。您需要将其设置为在文本框具有焦点时显示(然后在找到匹配项时隐藏),或者在失去焦点时执行某些操作但不要在每次按键时切换。