扫码枪页面,进入页面默认第一个框,扫完后跳第二个框
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$("#VIN").focus();
function keyDown(e){
//IE内核浏览器
if (navigator.appName == 'Microsoft Internet Explorer'){
var keycode = event.keyCode;
var realkey = String.fromCharCode(event.keyCode);
}else {//非IE内核浏览器
var keycode = e.which;
var realkey = String.fromCharCode(e.which);
}
// console.log('按键码:' + keycode + '字符: ' + realkey);
//监听Ctrl键
if(keycode==17){
$("#VIN").focus();
$("#VIN").select();
}
$("#VIN").change(function(){
console.log($(this).val());
$("#KNR").focus();
})
}
document.οnkeydοwn=keyDown;
function focusNextInput(thisInput){
var inputs = document.getElementsByTagName("input");
for(var i = 0;i<inputs.length;i++){
// 如果是最后一个,则焦点回到第一个
if(i==(inputs.length-1)){
inputs[0].focus();
break;
}else if(thisInput == inputs[i]){
inputs[i+1].focus();
break;
}
}
}
function subform(){
alert("表单提交");
$("#form1").submit();
}
</script>
</head>
<body>
<table>
<form id="form1">
VIN:<input id="VIN" name="VIN" type="text" οnkeypress="if(event.keyCode==13) focusNextInput(this);" autofocus="autofocus">
KNR:<input id='KNR' name="KNR" type="text" οnkeypress="if(event.keyCode==13) subform();">
</form>
</table>
</body>
</html>