如何在 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>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP