[英]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.
我想允许用户按Enter键并保存textarea的文本,但是我不希望换行符应用于textarea的文本中。 Is that possible?
那可能吗?
Here is my jsFiddle . 这是我的jsFiddle 。
e.stopPropagation();
just seems to be not enough! 似乎还不够!
What you're after is e.preventDefault()
. 您追求的是
e.preventDefault()
。 Stop propagation just stops bubbling up the DOM tree. 停止传播只是停止冒泡DOM树。
Try this: 尝试这个:
$('#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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.