MVC3 input button triggered by Enter button

2019-04-11 00:03发布

I have an ASP.NET MVC 3 C#.NET web application and I want the Enter button to trigger a particular Save button on my form. How would I do that?

1条回答
时光不老,我们不散
2楼-- · 2019-04-11 00:22

What I would do is utilize JavaScript for this one. Handle the onkeypress even of the form. Like so:

<form onkeypress="yourKeyPressFunction(event)">
...
</form>

Then your yourKeyPressFunction() would look something like this:

function yourKeyPressFunction(e)
{
    if (e.keyCode == 13)
    {
        // submit or do what you'd like when you hit enter
    }

    // ... so on and so forth
}
查看更多
登录 后发表回答