[英]Is there any HTML element that can preserve windows CRLF, i.e \r\n
span
), the CRLF is lost.但是,有一个用例,源数据包含 windows CRLF,当它呈现到文本框时(我使用了span
),CRLF 丢失了。 So the index is always offset by 1 per line.所以索引总是每行偏移 1。I know potentially we can fix it from the backend, but it would be nice and more consistent if we can preserve the CRLF on the web page.我知道我们可能可以从后端修复它,但是如果我们可以在网页上保留 CRLF 会更好且更一致。
Example code:示例代码:
var input = "Hello\\r\\nJavaScript!" document.getElementById("demo").innerHTML = input; var test = document.getElementById("demo").innerHTML console.log('length of input:' + input.length) console.log("length of test: " + test.length)
span.demo { white-space: pre-wrap; }
<span class="demo" id="demo">
input.length==test.length
我想看input.length==test.length
I have explored different fashion of white-space
style(including pre), but no luck.我探索了不同white-space
风格(包括 pre),但没有运气。
The console.log
might not be very clear for this purpose, but you can use Firefox debuger to watch the input
variable and see \\r\\n
.为此, console.log
可能不是很清楚,但您可以使用 Firefox 调试器查看input
变量并查看\\r\\n
。
Thanks a lot非常感谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.