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.
精彩评论