HTML DOM whiteSpace 屬性
定義和用法
whiteSpace 屬性設(shè)置如何處理文本中的空白符(比如空格和換行符)。
語法:
Object.style.whiteSpace=normal|nowrap|pre
可能的值
值 | 描述 |
---|---|
normal | 默認(rèn)?瞻讜粸g覽器忽略。 |
pre | 空白會被瀏覽器保留。其行為方式類似 HTML 中的 <pre> 標(biāo)簽。 |
nowrap | 文本不會換行,文本會在在同一行上繼續(xù),直到遇到 <br> 標(biāo)簽為止。 |
實(shí)例
本例不允許在文本內(nèi)換行:
<html>
<head>
<script type="text/javascript">
function removeWrapping()
{
document.getElementById("div1").style.whiteSpace="nowrap";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
<br />
<input type="button" onclick="removeWrapping()"
value="Do not let the text wrap" />
</body>
</html>