简体   繁体   English

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

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

I've been stuck on this issue. 我一直停留在这个问题上。 I have a simple form: 我有一个简单的表格:

<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>

I'm using a barcode scanner to enter the data into the text field. 我使用的条形码扫描仪的数据输入到文本字段中。 The scanner records a series of numbers, followed by a 'Enter' command. 扫描仪记录一系列数字,然后输入“ Enter”命令。

When I scan into the barcode1 field, it works perfectly, the form is submitted by the scanner's 'Enter' command. 当我扫描到条形码1字段时,它可以正常工作,该表单是由扫描仪的“输入”命令提交的。

When I scan into barcode2 field, it submits the form using the barcode1 submit. 当我进入扫描条形码2场,它使用条形码1提交提交表单。

Is it possible, to change the default submit button on a form with multiple submit buttons? 是否可以更改具有多个提交按钮的表单上的默认提交按钮? Perhaps I could set the default submit button when I focus on the text field for that submit button. 也许我可以设置默认的提交按钮,当我专注于文本字段为提交按钮。

Something like this? 像这样吗

$(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();
        }
    });

});

Fiddle 小提琴

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

相关问题 条形码扫描仪和2个提交按钮 - Barcode scanner and 2 submit buttons 在表单输入上按Enter键并更改默认操作(提交表单) - Pressing enter on form input and changing default action (submit form) 当不是默认表单操作时,如何使用JavaScript或jQuery通过Enter键提交表单 - How do I use JavaScript or jQuery to submit a form by using the Enter key, when not the default form action 按下回车键和多个提交按钮 - Pressing the enter key with multiple submit buttons 提交表单,没有操作属性按Enter键 - Submit form with no action atribute pressing enter key 来自条形码扫描仪的具有多个值的简单 HTML 表单输入字段 - Simple HTML form input field with multiple values from barcode scanner HTML 表单 - 使用添加 Enter (CR) 后缀的条形码扫描仪防止表单提交输入 - HTML Form - Prevent Form Submission For Input Using Barcode Scanner that adds Enter (CR) Suffix 当我有多个可能的提交按钮时,如何在ENTER上执行表单提交? - How can I do a form submit on ENTER when I have multiple possible submit buttons? 当我使用 jQuery 在 asp.net 中按 Enter 键时,如何找到两个默认提交按钮? - How to find two default submit buttons when i press the Enter key in asp.net using jQuery? 禁用表单中选定提交按钮的回车键 - Disabling enter key for selected submit buttons within a form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM