หากต้องการตั้งค่ารูปแบบของเส้นใน JavaScript ให้ใช้คุณสมบัติ textDecorationStyle คุณสามารถตั้งค่า underline, double, หรือ overline เป็นต้นสำหรับรูปแบบเส้น
ตัวอย่าง
คุณสามารถลองรันโค้ดต่อไปนี้เพื่อคืนค่ารูปแบบของเส้นในการตกแต่งข้อความด้วย JavaScript −
<!DOCTYPE html> <html> <body> <div id = "myText" style = "text-decoration: underline;"> This is demo text. </div> <br> <button onclick = "display()"> Set Text Decoration </button> <script> function display() { document.getElementById("myText").style.textDecorationColor = "red"; document.getElementById("myText").style.textDecorationStyle = "double"; } </script> </body> </html>