如何在 JavaScript 中為非 CJK 語言設定換行規則?


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

更新於:23-6 月 2020 年

197 次瀏覽

開啟你的 職業生涯

透過完成課程獲取認證

入門
廣告
© . All rights reserved.