Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าการจัดตำแหน่งบรรทัดสุดท้ายเมื่อ text-align เป็น justify ด้วย JavaScript


ใช้คุณสมบัติ textAlignLast ใน JavaScript เพื่อตั้งค่าบรรทัดสุดท้ายให้เป็น right ตั้งค่าเป็น right เพื่ออนุญาตการจัดตำแหน่งขวา

ตัวอย่าง

คุณสามารถลองรันโค้ดต่อไปนี้เพื่อคืนค่าการจัดตำแหน่งของบรรทัดสุดท้ายของบล็อกหรือบรรทัดก่อนการขึ้นบรรทัดใหม่บังคับเมื่อ text-align เป็น "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.          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>