如何在 JavaScript 中设置非 CJK 脚本的换行规则?
javascriptobject oriented programmingfront end technology更新于 2024/6/21 21:00:17
使用 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>
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

