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

วิธีตั้งค่าทิศทางข้อความ (Text Direction) ด้วย JavaScript

ใช้คุณสมบัติ direction เพื่อกำหนดทิศทางการไหลของข้อความ ค่า ltr (ซ้ายไปขวา - ค่าเริ่มต้น), rtl (ขวาไปซ้าย)

ตัวอย่าง

<!DOCTYPE html>
<html>
  <body>
    <h1 id="myID">Heading 1</h1>
    <p>Click below to set the direction of heading to Left-to-right</p>
    <button type="button" onclick="display()">Click to change the direction</button>
    <script>
      function display() {
        document.getElementById("myID").style.direction = "rtl";
      }
    </script>
  </body>
</html>