JavaScript 参考手册
Style wordWrap 属性
允许长单词换行到下一行
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <style> #myDIV { width: 150px; height: 100px; background-color: lightblue; border: 1px solid black; } </style> </head> <body> <p>点击“尝试一下”按钮。让 DIV 元素中的长单词换行到下一行:</p> <div id="myDIV">Thiscouldbeaninsainlylargeword</div> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { document.getElementById("myDIV").style.wordWrap = "break-word"; } </script> </body> </html>
运行结果:
点击运行 »