开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜