我已经尝试过使用以下的
通过连续组合使用
以下是我的
如何在HTML的
\r
和\n
组合,但没有成功:
<textarea rows="10" readonly><?php echo 'First line.\r\nSecond line.'; ?></textarea>
通过连续组合使用
和
,我能够在各种浏览器中实现我的目标,但当使用w3验证器进行验证时,出现了以下HTML5验证错误:
另一方面,在错误:数字字符引用扩展为回车符。
<textarea>
中使用常规换行并应用以下CSS规则,我没有收到任何验证错误;但这种方法的挑战在于它不是跨浏览器兼容的(特别是不被Internet Explorer和Edge支持)。textarea {
white-space: pre-line;
}
以下是我的
<textarea>
元素的内容:<!-- First approach, as described above. -->
<textarea rows="10" readonly><?php echo 'First line. Second line.'; ?></textarea>
<!-- Here, the second one, in combination with the white-space: pre-line; CSS rule. -->
<textarea rows="10" readonly><?php echo 'First line.
Second line.'; ?></textarea>
如何在HTML的
<?= "第一行。\r\n第二行。"; ?>
。 - CD001"
而不是'
,它会有所不同... 它们是不同的东西:http://php.net/manual/en/language.types.string.php - CD001