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

末鹿安然 提交于 2019-12-17 22:17:51

问题


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/questions/5842813/how-can-i-only-allow-shiftenter-to-return-new-line-in-text-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!