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
}