开发者

Is it true that HTML forms cannot submit (with enter) if theres no submit button?

开发者 https://www.devze.com 2023-02-04 16:32 出处:网络
I find that if I have a form with no submit button, it will not submit (with enter key). But if I add a submit button, it works

I find that if I have a form with no submit button, it will not submit (with enter key). But if I add a submit button, it works

No submit button http://jsfiddle.net/VxF42/1/

With submit button http://jsfiddle.net/VxF42/

I am alittle confused as to why this works -> 1 form element / no submit button

http://jsfiddle.net/VxF42/1/

It seems like if I have a form with more than 1 form element, I need a submit button? How can I have开发者_JS百科 no submit button. I will be using jQuery UI Dialog's Buttons


Is it true that HTML forms cannot submit (with enter) if theres no submit button?

Depends on how you code. By default this won't happen.

But you can use javascript to triger the submit event of a form by handling keyboard event and checking for enter key.


No, that's not true.

It seems that as long as an input element (or any other applicable form-related element, I think) that is the child of a form element has focus, hitting the enter key submits the form.

<form>
 <input>
</form>

Tested that in Firefox 4, IE 8, Chrome 9, Opera 10, and Safari 5.


in jquery, you can use the .submit() method on an input element I believe. I know I've done this same thing without a submit button.

0

精彩评论

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