HTML表单,包含2个(隐藏的)提交按钮和1个其他隐藏的输入
HTML form with 2 (hidden) submit buttons and 1 other hidden input
我正在尝试构建这个应用程序,在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 ?
相关文章:
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- PHP Javascript显示/隐藏按钮不工作
- 如何隐藏按钮单击事件上的占位符
- 我的表单上的SpringWebFlow2中的每个转换都需要隐藏按钮吗
- 使用ng-hide根据条件显示/隐藏按钮
- 另一种显示和隐藏按钮的方式
- PHP If Else-隐藏按钮
- 如何显示/隐藏按钮
- jQuery 隐藏按钮,如果它们不包含文本
- 如何检测是否在主页上隐藏按钮
- 单击时隐藏按钮
- 在可丢弃的::javascript上显示隐藏按钮
- 想要使用onclick显示隐藏按钮
- 使用jQuery在ruby中显示/隐藏按钮
- 如果未输入URL,则隐藏按钮
- 当按下第二个按钮时如何隐藏按钮,以及当我点击页面的空白区域时如何使其出现
- 如何使用onmouseover和onmouseout在鼠标经过按钮时隐藏和取消隐藏按钮
- 使用运行时创建的链接来触发ASP.Net中隐藏按钮的单击处理程序
- 如何在ajax响应中隐藏按钮
- 切换时隐藏按钮