textarea 显示纯文本_在html textarea中显示换行符(Show newlines in html textarea)

问题来自于换行符(\ n \ r?)与HTML
标签不同的事实 var text = document.forms[0].txt.value;

text = text.replace(/\r?\n/g, '
');

Problem comes from the fact that line breaks (\n\r?) are not the same as HTML
tags var text = document.forms[0].txt.value;

te...

规格不允许换行或回车字符。 占位符属性表示旨在帮助用户进行数据输入的简短提示(一个单词或短语)。 提示可能是样本值或预期格式的简要说明。 属性(如果指定)必须具有不包含U + 000A LINE FEED(LF)或U + 000D CARRIAGE RETURN(CR)字符的值。 显然,建议使用title属性更长。 对于更长的提示或其他咨询文本,标题属性更合适。 The specification does not allow line feed or carriage return charac...

设置value不是innerText ; $("#ConfirmEmailText").val("test\n\ntest\ntest");

Set the value not the innerText; $("#ConfirmEmailText").val("test\n\ntest\ntest");

他们几乎肯定不会被转换为新行,问题很可能就是您展示他们的方式。 尝试使用linebreaks过滤器在您的模板中显示它们,如下所示: {{ mypost.body|linebreaks }}

They're almost certainly not being converted to new-lines, the problem is likely to be the way you're displaying them. Try displaying them in your template...

删除wrap属性。 这是不需要的。 Remove the wrap attribute. It’s unneeded.

现场演示

#myform textarea {

border: 1px solid #000;

position: absolute;

}

#myform #source {

background: transparent;

z-index: 1;

}

#myform #mirror {

color: rgba(0,0,0,0.5);

z-index: -1;

}

Use as a line break. Like this :

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值