[英]jquery add <br> after click enter in textarea
I'm trying to append a br
tag after a user click enter in a textarea field. 我试图在用户单击textarea字段中的enter后附加
br
标签。
This is what I'm trying to do: 这就是我想要做的:
if (e.keyCode == 13)
{
$('.myTextarea').replace('\n', "<br />");
}
Can anyone tell me what I'm doing wrong? 谁能告诉我我在做什么错?
You should get value in the textarea. 您应该在文本区域中获得价值。 See the val document http://api.jquery.com/val/ .
请参阅val文档http://api.jquery.com/val/ 。
Try this, 尝试这个,
if (e.keyCode == 13)
{
$('.myTextarea').val(function(i, v) {
return v.replace('\n', '<br/>');
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.