Enter 按钮的行为与 MVC2 中的按钮单击不同

发布于 2024-12-14 20:00:11 字数 283 浏览 3 评论 0原文

我有一个 MVC2 项目,其中有一个页面应该调用 jquery 函数。当您通过鼠标单击按钮时,我的 jquery 函数将被调用。当然,我的按钮 ID 上有一个 .click() 函数调用。我的猜测是,当我按 Enter 键时,我只是执行表单提交,而不是执行单击动作。有没有一种方法可以让回车按钮做与 .click() 相同的事情,或者至少使用 jquery 或任何事实上的东西来禁用回车按钮,以便用户无法按回车键并且将有通过鼠标按下?

任何想法将不胜感激。与此同时,我将继续在互联网上搜索,找出我能为此做些什么。

谢谢。

I have an MVC2 project that has a page on it that is supposed to call a jquery function. When you click on the button via the mouse my jquery function is called. I of course have a .click() function call on my button ID. My guess is that I am simply performing a form submit when I press enter instead of going through the click motion. Is there a way that I can either have the enter button do the same thing as the .click() or at least use jquery or anything as a matter of fact to disable the enter button so that a user can not hit enter and will have to press via the mouse?

Any ideas will be greatly appreciated. In the meantime, I will continue to scour the internet to figure out what I can do for this.

thanks.

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

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

发布评论

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

评论(2

菩提树下叶撕阳。 2024-12-21 20:00:11

我认为您应该能够挂钩表单 submit 事件:

$('#myForm').submit(function() {
...
});

使用它应该可以处理单击按钮或按 Enter 键。

I would think that you should be able to just hook into the forms submit event:

$('#myForm').submit(function() {
...
});

Using this should handle either the button click or an enter key press.

暮年 2024-12-21 20:00:11

试试这个

$("#frmEdit").keypress(function (event) {

    if (event.which == 13 && event.target.nodeName != "TEXTAREA") {
        $('#btnSubmit').click();
        event.preventDefault();
    }

});

该函数查找除 TextArea 之外的所有控件的 Enter 键按下并调用提交事件。

Try this

$("#frmEdit").keypress(function (event) {

    if (event.which == 13 && event.target.nodeName != "TEXTAREA") {
        $('#btnSubmit').click();
        event.preventDefault();
    }

});

This function looks for enter key press for all controls except TextArea and calls a submit event.

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