MVC3 input button triggered by Enter button

社会主义新天地 提交于 2019-12-06 04:39:14

问题


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:


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
}


来源:https://stackoverflow.com/questions/8609935/mvc3-input-button-triggered-by-enter-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!