在JavaScript中使用wordbreak属性可为非CJK脚本设置换行规则。以下是CJK脚本:C代表中文,J代表日语,K代表朝鲜语。
您可以尝试运行以下代码以了解如何实现wordbreak属性-
<!DOCTYPE html> <html> <head> <style> #box { width: 150px; height: 120px; background-color: lightblue; border: 1px solid black; } </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.This is Demo Text. </div> <script> function display() { document.getElementById("box").style.wordBreak = "break-all"; } </script> </body> </html>