如何在 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