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 line, 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?? Thank you. 回答1: $("textarea").keydown(function(e){ // Enter was pressed without shift key if (e.keyCode == 13 && !e.shiftKey) { // prevent default behavior e.preventDefault(); } }); Try the jsFiddle. 来源: https://stackoverflow.com