问题来自于换行符(\ 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 :