如何在JavaScript中处理制表符,换行符和空格?
要在文本中处理制表符,换行符和空格,请使用JavaScript中的whitespace 属性。设置值normal,nowrap,pre等。设置pre时,它的作用类似于<pre>标记。文本只会换行。
示例
您可以尝试运行以下代码,以了解如何使用JavaScript中的whitespace 属性
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 300px;
height: 100px;
border: 2px solid black;
background-color: gray;
}
</style>
</head>
<body>
<button onclick="display()">Set</button>
<div id="box">
This is Demo Text.
This is Demo Text.
This is Demo Text.
This is Demo Text.
This is Demo Text.
</div>
<script>
function display() {
document.getElementById("box").style.whiteSpace = "pre";
}
</script>
</body>
</html>热门推荐
10 给孩子祝福语简短创意
11 白族结婚祝福语简短大全
12 生日祝福语送老公简短
13 对女儿生日祝福语简短
14 中考祝福语给同学简短
15 生日祝福语陌生女生简短
16 小学立秋祝福语大全简短
17 旅游祝福语简短老师发言
18 送病人简短的祝福语