禁用键盘输入 条形码扫描

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html

xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title>      <SCRIPT>           var KeyCode = {              EnterKey    : 13,                DLE         : 16,                EscKey      : 27,              PageUpKey   : 33,              PageDownKey : 34,             EndKey      : 35,             HomeKey     : 36,              LeftArrow   : 37,               UpArrow     : 38,               RightArrow  : 39,                DownArrow   : 40,               InsertKey   : 45,              DeleteKey   : 46          }                    </SCRIPT>     <SCRIPT type="text/javascript">          function log(msg){           Output.innerHTML+=msg;        }               var previous=0;        var limit = 100;        var timeout_id;       function error(){              log("please use barcode scanner"+"<br/>");            document.getElementById("barcode_only").value = "";             document.getElementById("barcode_only").focus();               previous=0;                   }               function blocker(){           var dt = (new Date()).getTime();                   log(dt+":"+event.keyCode+"<br/>");                       if (event.keyCode==KeyCode.DLE) return true;                             if (previous==0) {             previous=dt;             timeout_id = setTimeout("error()",100);             return true;         }          else if (dt-previous>limit) {              error();               clearTimeout(timeout_id);             return false;                      }         else{              previous=dt;               clearTimeout(timeout_id);           }       }       function try_again(){       previous=0;        Output.innerHTML="";       document.getElementById("barcode_only").value="";       document.getElementById("barcode_only").focus();       }          </SCRIPT>  

</head> <body>     <form id="form1" runat="server">     <div>     <asp:TextBox ID="barcode_only" onkeyup="blocker(this)" runat="Server"></asp:TextBox> <INPUT onclick=try_again() type=button value="try again!"><BR>    <DIV id=Output></DIV>     </div     </form> </body> </html>

你可能感兴趣的:(条形码)