HTML表单,包含2个(隐藏的)提交按钮和1个其他隐藏的输入

HTML form with 2 (hidden) submit buttons and 1 other hidden input

本文关键字:隐藏 按钮 1个 其他 输入 提交 2个 包含 表单 HTML      更新时间:2023-09-26

我正在尝试构建这个应用程序,在Android平板电脑上运行的条形码扫描器附加。条码扫描器在每个扫描码后发送一个Enter。

我需要扫描2个条形码并提交表格。

我创建了一个表单,有两组输入+提交按钮,第二组隐藏。扫描第一个条形码后,扫描仪发送Enter键,隐藏的元素被显示出来,我可以扫描第二个条形码。然而,第二次回车键不起作用。它只工作,如果我按下按钮(在我取消隐藏它)。我怎么能照顾到这一点,所以它不需要用户输入(除了扫描条形码)?

下面是目前为止的代码:
    <form action="barcode.php" method="post" class="pure-form" style="width:100%">
        <fieldset>
            <legend>Scaneaza o fisa noua de <?php echo $operation; ?>:</legend>
            <input type="text" name="barcode" autofocus id="InputID" placeholder="Codul de bare" style="width:100%;font-size:2em">
            <button style="width:0;visibility:hidden;" type="submit" onclick="show_popup('my_popup'); return false;"></button>
                <div id="my_popup" style="display:none;border:3px dotted gray;padding:.3em;background-color:white;position:absolute;width:80%;height:20%;margin:-50px 50px 0 50px;">
                    <legend>Introdu numarul de KO-uri:</legend>
                    <input type="text" name="kos" autofocus id="InputID" placeholder="KO-uri" style="width:100%;font-size:2em">
                    <button type="submit" class="pure-button pure-button-primary" style="/*width:0;visibility:hidden;*/" onclick="hide_popup('my_popup'); return true;">Trimite</button>
                </div>
        </fieldset>
    </form>
    <script type="text/javascript">
        function FocusOnInput() { document.getElementById("InputID").focus(); }
        function show_popup(id) {
            if (document.getElementById){
                obj = document.getElementById(id);
                if (obj.style.display == "none") {
                    obj.style.display = "";
                }
            }
        }
        function hide_popup(id){
            if (document.getElementById){
                obj = document.getElementById(id);
                if (obj.style.display == ""){
                    obj.style.display = "none";
                }
            }
        }
    </script>

和bar .php文件:

    <?php
    ob_start();
    mysql_connect ("localhost","root","root") or die (mysql_error());
    mysql_select_db ("eficacitate");
    $barcode = $_POST["barcode"];
    $kos    = $_POST["kos"];
    $marca    = $_COOKIE["marca"];
    $operation = $_COOKIE["operation"];
    if (substr($barcode,0,1)=="^") {
    $j_nou =    substr($barcode,1,strpos($barcode, "|")-1);
    $parts = explode('|',$barcode);
    $of_nou = $parts[1];
    $cantitate_nou = $parts[2];
    $serie_nou = $parts[3];
    $adauga="INSERT INTO master (marca, operation,j,of,cantitate,serie,kos)
    VALUES
    ('$marca','$operation','$j_nou','$of_nou','$cantitate_nou','$serie_nou','$kos')";
    mysql_query($adauga);
    }
    header('Location: /eficacitate/scan.php');
    ob_flush();
    ?>

请尝试一下:

<form action="barcode.php" method="post" class="pure-form" style="width:100%">
<fieldset>
    <legend>Scaneaza o fisa noua de <?php echo $operation; ?>:</legend>
    <input type="text" name="barcode" autofocus id="InputID" placeholder="Codul de bare" style="width:100%;font-size:2em">
    <button id='barcodeButton' style="width:0;visibility:hidden;" type="submit" onclick="show_popup('my_popup'); return false;"></button>
    <div id="my_popup" style="display:none;border:3px dotted gray;padding:.3em;background-color:white;position:absolute;width:80%;height:20%;margin:-50px 50px 0 50px;">
        <legend>Introdu numarul de KO-uri:</legend>
        <input type="text" name="kos" autofocus id="InputID" placeholder="KO-uri" style="width:100%;font-size:2em">
        <button id='kosButton' type="submit" class="pure-button pure-button-primary" style="/*width:0;visibility:hidden;*/" onclick="hide_popup('my_popup'); return true;">Trimite</button>
    </div>

<script type="text/javascript">
    function FocusOnInput() { document.getElementById("InputID").focus(); }
    document.onkeydown = function(event) {
        if (event.keyCode == '13') { 
            barcodeButton = document.getElementById('barcodeButton');
            kosButton = document.getElementById('kosButton');
            if (document.getElementById('my_popup').style.display == 'none') {
                barcodeButton.click();
                show_popup('my_popup');
            } else {
                kosButton.click();
                hide_popup('my_popup');
            }
        }
    }
    function show_popup(id) {
        if (document.getElementById){
            obj = document.getElementById(id);
            if (obj.style.display == "none") {
                obj.style.display = "";
            }
        }
    }
    function hide_popup(id){
        if (document.getElementById){
            obj = document.getElementById(id);
            if (obj.style.display == ""){
                obj.style.display = "none";
            }
        }
    }

让我知道这是否解决了你想要达到的目标。出于好奇,为什么不在这里使用jQuery ?