如何在 JavaScript 中设置最后一行块或强制换行前一行在 "justify" 文本对齐下的对齐方式?
在 JavaScript 中使用 textAlignLast 属性将最后一行设置为 right。将其设置为 right 并允许右对齐。
示例
你可以尝试运行以下代码,以返回当 “justify” 文本对齐的情况下如何通过 JavaScript 对齐最后一行块或强制换行前的一行 −
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
text-align: justify;
}
</style>
</head>
<body>
<div id = "myText">
This is demo text. This is demo text. This is demo text. This is demo text.
This is demo text. This is demo text. This is demo text. This is demo text.
This is demo text. This is demo text. This is demo text. This is demo text.
This is demo text. This is demo text. 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>
<button onclick = "display()"> Set Alignment </button>
<script>
function display() {
document.getElementById("myText").style.textAlignLast = "right";
;
}
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP