Submit value on pressing Enter in textarea and pressing Shift+Enter should go to next line

前端 未结 3 825
一个人的身影
一个人的身影 2021-01-05 07:39

I want to have a chat box (textarea) where if user press Enter then it should submit the chat, and if user press Shift+Enter then it should enter in a new line.

I tr

3条回答
  •  一个人的身影
    2021-01-05 08:02

    $("textarea").keydown(function(e)
    {
        if (e.keyCode == 13)
        {
            if (e.shiftKey) {
                $(this).val( $(this).val() + "\n" );
            }
            else {
                submitTheChat();
            }
        }
    });
    

提交回复
热议问题