如何允许长而坚不可摧的单词被折断并包装到JavaScript中的下一行?
使用JavaScript中的 wordWrap属性可将长单词分解并换行到下一行。
示例
您可以尝试运行以下内容以学习如何使用wordWrap 属性-
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 150px;
height: 150px;
background-color: lightblue;
border: 1px solid black;
}
</style>
</head>
<body>
<button onclick = "display()">Set</button>
<div id = "box">
ThisisDemoText.ThisisDemoText.ThisisDemoText.ThisisDemoText.Thisis DemoText.ThisisDemoText.
</div>
<script>
function display() {
document.getElementById("box").style.wordWrap = "break-word";
}
</script>
</body>
</html>热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短