使用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>