【发布时间】:2016-06-22 10:46:59
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).keypress(
function(event){
if (event.which == '13') {
event.preventDefault();
$("#j").focus();
}
});
</script>
</head>
<body>
<form id = "form1" action ='<?php echo $_SERVER['PHP_SELF']; ?>' method = "post">
<input type = "text" name = 'i' id = 'i' autofocus>
<input type = "text" name = 'j' id = 'j'>
<input type = "submit" name = 'submit' value = 'submit'>
</form>
</body>
</html>
<?php
echo $_POST['i'];
echo $_POST['j'];
?>
在上面的代码中,我最初禁用了输入按键事件。我正在使用已经给出回车的条形码扫描仪。这让我可以在使用条形码扫描仪扫描第一个输入字段后专注于下一个输入字段。但是,我希望在第二个字段通过扫描仪输入数据时提交表单。我如何实现这一目标?
【问题讨论】:
标签: javascript php jquery