我需要抑制什么事件才能阻止 IE “Dinging”? 当我在文本框中按 Enter 键时?

发布于 2024-07-23 20:22:54 字数 597 浏览 7 评论 0原文

在带有一个文本框的简单表单上,按 Enter 键即可提交表单(这对于轻松搜索表单来说非常有用)

但是,在具有多个字段的表单上,在 input="text" 框中按 Enter 键不会提交表单做任何事情(例如提交),但在 IE 中它会“叮”一声,就好像您试图删除一个不可删除的对象一样。

问题是...我需要在 IE 中抑制什么事件才能停止这种声音? 例如,如果我有一个用户名/密码表单,我确实希望使用回车键来提交表单,但我当然不希望听到“错误”声音。

带有声音的示例站点: http://www.sears.com/shc/s/StoreLocatorView ?storeId=10153&catalogId=12605 只需在任意文本字段中按 Enter 键即可。 叮!、叮!、叮!

非IE用户,声音是:Program Events > 窗口> 默认蜂鸣声(“Windows XP Ding.wav”)

On simple forms with one text box pressing enter submits the form (and this is great for easy search forms)

However on a form with multiple fields, pressing Enter in an input="text" box won't do anything (e.g. submit) but in IE it "Dings" as if you have tried to delete an undeletable object.

The question is... what event do I need to suppress in IE to stop this sound? e.g. if I have a username/password form, I DO want the enter key to submit the form, but I certainly don't want the "error" sound.

Example site with the sound:
http://www.sears.com/shc/s/StoreLocatorView?storeId=10153&catalogId=12605
Just press Enter in any of the text fields. Ding!, Ding!, Ding!

Non-IE users, the sound is the: Program Events > Windows > Default Beep ("Windows XP Ding.wav")

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

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

发布评论

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

评论(5

送君千里 2024-07-30 20:22:54

看来这可行:

<!-- suppress sound (and suppress submit) -->
<input type="text" onkeypress="if(window.event.keyCode == 13){return false;}"/>

<!-- suppress sound (BUT allow submit) -->
<input type="text" onkeypress="if(window.event.keyCode == 13){this.form.submit();return false;}"/>

Well it appears that this works:

<!-- suppress sound (and suppress submit) -->
<input type="text" onkeypress="if(window.event.keyCode == 13){return false;}"/>

<!-- suppress sound (BUT allow submit) -->
<input type="text" onkeypress="if(window.event.keyCode == 13){this.form.submit();return false;}"/>
执手闯天涯 2024-07-30 20:22:54
$("#logonForm").keypress(function (e) {
            if (e.keyCode == '13') {
                if (instance.Validate(instance)) {
                    document.forms["logonForm"].submit();
                    return false;  //Do not delete, suppresses ding in IE... :P
                }
            }
        });

这有效,我们使用它。

$("#logonForm").keypress(function (e) {
            if (e.keyCode == '13') {
                if (instance.Validate(instance)) {
                    document.forms["logonForm"].submit();
                    return false;  //Do not delete, suppresses ding in IE... :P
                }
            }
        });

This works, we use it.

淡淡離愁欲言轉身 2024-07-30 20:22:54

他是对的。 你想要的文本字段,不是为了用丁歌来烦你,

只是添加

onkeypress="if(window.event.keyCode == 13){return false;}"

到你的输入标签中

<input type="whatever"  onkeypress="if(window.event.keyCode == 13){return false;}" >

,但不要在提交或按钮输入中这样做,就可以了。 仅适用于文本字段,这样您就不会因为叮叮而烦恼! 叮! 现在。
我检查了。

He is right. The text field you want, not to annoy you with ding song

only add

onkeypress="if(window.event.keyCode == 13){return false;}"

to you input tag

<input type="whatever"  onkeypress="if(window.event.keyCode == 13){return false;}" >

But don't do this in submit or button input ok. Only to the text fields, so you don't get annoyed by ding! ding! now.
I checked.

梨涡少年 2024-07-30 20:22:54
$("#txtSomething").keypress(function (e) {
        if (e.which == 13) {

            e.Handled = true; //This will prevent the "ding" sound

            //Write the rest of your code
        }
    });
$("#txtSomething").keypress(function (e) {
        if (e.which == 13) {

            e.Handled = true; //This will prevent the "ding" sound

            //Write the rest of your code
        }
    });
固执像三岁 2024-07-30 20:22:54

我想这是由操作系统和操作系统控制的。 因此,它不能使用 javascript 进行控制。

I guess that is controlled by OS & hence, it cant be controlled using javascript.

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