开发者

HTML form - normal button prevents submitting the form on Enter

开发者 https://www.devze.com 2023-01-25 15:13 出处:网络
I have a form with some <button> elements and a normal <input type=\"submit\"> button to submit the form.

I have a form with some

<button>

elements and a normal

<input type="submit">

button to submit the form.

However, when I press Enter when I'm in a textfield, the form does not get submitted but much rather the first Element is "pressed".

开发者_如何学编程

How can I change this behavior?


I would recommend changing the <button> tag and turning it into an <input type="button" /> tag. This should force the form to submit the way you want.


You can use javascript to capture that the Enter key was pressed and submit the form.

See this example.

For a complete answer, could you please post your HTML?

0

精彩评论

暂无评论...
验证码 换一张
取 消