คุณสมบัติ placeholder ของ HTML DOM Input Number ใช้สำหรับคืนค่าและเปลี่ยนแปลงค่าของแอตทริบิวต์ placeholder ของช่องป้อนตัวเลข
รูปแบบไวยากรณ์ (Syntax)
การคืนค่า placeholder
object.placeholder
การเปลี่ยนแปลง placeholder
object.placeholder = “text”
ตัวอย่าง
ตัวอย่างการใช้งานคุณสมบัติ placeholder ของ HTML DOM Input Number:
<!DOCTYPE html> <html> <head> <style> html{ height:100%; } body{ text-align:center; color:#fff; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat; height:100%; } p{ font-weight:700; font-size:1.1rem; } input{ display:block; width:35%; border:2px solid #fff; background-color:transparent; color:#fff; font-weight:bold; padding:8px; margin:1rem auto; } .btn{ background:#0197F6; border:none; height:2rem; border-radius:2px; width:35%; margin:2rem auto; display:block; color:#fff; outline:none; cursor:pointer; } </style> </head> <body> <h1>ตัวอย่างคุณสมบัติ placeholder</h1> <p>สวัสดีครับ ป้อนอายุของคุณ:</p> <input type="number" class="numberInput" placeholder="ป้อนอายุของคุณ"> <button type="button" onclick="change()" class='btn'>เปลี่ยน Placeholder</button> <script> function change() { var numberInput = document.querySelector(".numberInput"); numberInput.placeholder = "กรุณาป้อนอายุของคุณ"; } </script> </body> </html>
ผลลัพธ์
โค้ดด้านบนจะให้ผลลัพธ์ดังนี้:

คลิกปุ่ม 「เปลี่ยน Placeholder」 เพื่อเปลี่ยนค่าของ placeholder
