停止条形码扫描仪刷新页面

发布于 2025-01-07 05:34:24 字数 573 浏览 3 评论 0原文

我在 HTML 表单中使用条形码扫描仪,但页面刷新时出现问题

扫描仪的输入进入此表单 (html 5):

<form>
<label for "bar_code">Item</label>
<input
name="bar_code"
id="bar_code" 
onchange = "processBarCode('getitemdetails.php', this.value);"
onfocus="setStyle(this.id);"
autofocus
>
</form>

processBarCode 是一个 AJAX 函数,用于检查条形码是否在mySQL 数据库,如果将项目添加到页面下方的

中,则效果非常好。问题在于,由于条形码扫描仪在函数返回时在扫描末尾添加了一个回车键,因此会触发提交,从而导致页面刷新。

我需要添加输入以使 onchange 自动工作,但仍需要禁用页面刷新。

任何想法感激不尽!

I am using a barcode scanner in an HTML form and have a problem with the page refreshing

The scanner's input goes into this form (html 5):

<form>
<label for "bar_code">Item</label>
<input
name="bar_code"
id="bar_code" 
onchange = "processBarCode('getitemdetails.php', this.value);"
onfocus="setStyle(this.id);"
autofocus
>
</form>

The processBarCode is a AJAX function that checks if the barcode is in a mySQL database and if it is adds the item to a <form> further down the page, this works perfectly. The problem is that because the bar code scanner adds an enter to the end of the scan when the function returns it triggers a submit thus causing the page to refresh.

I need the added enter for the onchange to work automatically but still need to disable the page refresh.

Any ideas gratefully received!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年华零落成诗 2025-01-14 05:34:24

更改表单元素以取消提交:

<form onsubmit="return false;">

Change your form element to cancel the submit:

<form onsubmit="return false;">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文