如何使用 JavaScript 设置文本的水平对齐方式?

javascriptobject oriented programmingfront end technology更新于 2024/6/21 17:48:17

使用 JavaScript 中的 textAlign 属性,将其设置为 right,即可水平对齐。您可以尝试运行以下代码,使用 JavaScript − 返回文本的水平对齐方式

示例

<!DOCTYPE html>
<html>
   <body>
      <p id = "myText">This is demo text</p>
      <button onclick = "display()">Set Horizontal Alignment</button>
      <script>
         function display() {
            document.getElementById("myText").style.textAlign = "right";
         }
      </script>
   </body>
</html>

相关文章


有用资源