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

วิธีเปลี่ยนข้อความเป็น Subscript ด้วย JavaScript

ใช้เมธอด sub() ของ String ทำให้ข้อความแสดงเป็น subscript (ดัชนีล่าง) เหมือนแท็ก <sub>

ตัวอย่าง

<html>
  <head>
    <title>JavaScript String sub() Method</title>
  </head>
  <body>
    <script>
      var str = new String("Demo Text");
      document.write("This is subscript: " + str.sub());
    </script>
  </body>
</html>

ผลลัพธ์

<sub>Demo Text</sub>

String HTML Methods ทั้งหมด (Legacy)

ดูตารางครบในบทความ ID 1004055422 (link method)

แนะนำ: ใช้ CSS vertical-align: sub; หรือแท็ก <sub> โดยตรงใน HTML แทน