[英]Automatically submitting a HTML form after scanning a barcode
我試圖在掃描條形碼后自動提交表單。 我掃描的號碼總是 16 位數字。
<form id="Form" action="action.php" method="post">
<input id="here" maxlength="16" placeholder="scan..." type="text" tabindex="1" required autofocus>
<input id="subHere" type="submit">
</form>
<script>
$('#here').keyup(function(){
if(this.value.length ==16){
$('#subHere').click();
}
});
</script>
輸入 16 位數字的限制有效,但我的表單在輸入 16 位數字后不會自動提交。
我也想在提交后清除表格,以便我可以掃描下一個條形碼。 你有什么建議嗎?
感謝 Fr0zenFyr 它現在可以工作了:
<form id="Form" action="./js/filehandling.js" method="post">
<input id="here" maxlength="16" placeholder="scan..." type="text" tabindex="1" required autofocus>
<input id="subHere" type="submit">
</form>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script>
$('#here').keyup(function(){
if(this.value.length ==16){
$('#subHere').click();
}
});
</script>
輸入16位數字后,自動提交表單
另一種方法是:
<script>
$("#input_field").keyup(function() {
if ($(this).val().length >= 16)
$('#form').submit();
})
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.