How to submit a form on enter when the textarea has focus?

后端 未结 3 1674
天涯浪人
天涯浪人 2020-12-13 17:35

When filling out a form\'s textarea, the default behavior when the enter key is hit is to move to the next line. How can I change the behavior of the form so it will submit

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 18:00

    Why do you want a textarea to submit when you hit enter?

    A "text" input will submit by default when you press enter. It is a single line input.

    
    

    A "textarea" will not, as it benefits from multi-line capabilities. Submitting on enter takes away some of this benefit.

    
    

    You can add JavaScript code to detect the enter keypress and auto-submit, but you may be better off using a text input.

提交回复
热议问题