防止enter进入textarea

Prevent enter from entering textarea

I want to allow the user to press enter and save the text of the textarea, but I want the newline NOT to get applied in the text of the textarea. Is that possible?

这是我的jsFiddle

e.stopPropagation();

好像还不够!

你要找的是e.preventDefault()。停止传播只是停止在 DOM 树中冒泡。

我刚刚在 JSFiddle 中尝试了这段代码,对我来说效果很好

$('textarea').keypress(function(event) {
   if (event.keyCode == 10 || event.keyCode == 13) {
     event.preventDefault();
   }
});

你错过了 return false;

尝试here

试试这个:

$('#cagetextbox').keypress(function(e){return CancelNewLine(e);});

function CancelNewLine(e)
{
    var keynum;
    if(window.event) // IE
        keynum = e.keyCode;
    else if(e.which) // Netscape/Firefox/Opera
        keynum = e.which; 

    return (keynum != 13);
}