开发者

How can I only allow shift+enter to return new line in text area?

开发者 https://www.devze.com 2023-03-01 23:47 出处:网络
In a default behavior, the textarea \"press\" enter will become new line, but I don\'t want to having a new l开发者_Go百科ine, I want the user press shift+enter, instead. How can I do so? or... ... ca

In a default behavior, the textarea "press" enter will become new line, but I don't want to having a new l开发者_Go百科ine, I want the user press shift+enter, instead. How can I do so? or... ... can I return the textarea enter event before it actually fire to the text area?


$("textarea").keydown(function(e){
    // Enter was pressed without shift key
    if (e.key == 'Enter' && !e.shiftKey)
    {
        // prevent default behavior
        e.preventDefault();
    }
});

Try the jsFiddle.

0

精彩评论

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