繁体   English   中英

具有多个提交按钮的表单,如何设置默认的输入键操作-条形码扫描器输入

[英]Form with multiple submit buttons, how to set the default enter key action - barcode scanner input

我一直停留在这个问题上。 我有一个简单的表格:

<form>
<input type="text" name="barcode1">
<input type="submit" name="barcode1" value="Submit Barcode1">
<input type="text" name="barcode2">
<input type="submit" name="barcode2" value="Submit Barcode2">
</form>

我使用的条形码扫描仪的数据输入到文本字段中。 扫描仪记录一系列数字,然后输入“ Enter”命令。

当我扫描到条形码1字段时,它可以正常工作,该表单是由扫描仪的“输入”命令提交的。

当我进入扫描条形码2场,它使用条形码1提交提交表单。

是否可以更改具有多个提交按钮的表单上的默认提交按钮? 也许我可以设置默认的提交按钮,当我专注于文本字段为提交按钮。

像这样吗

$(document).ready(function() {
    var toClick;
    $(":text").focus(function() {
        toClick = $(this);
    });
    $('form').keypress(function(event) {
        if (event.keyCode == 13) {
            event.preventDefault();
            $(toClick).next('input[type="submit"]').click();
        }
    });

});

小提琴

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM