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

คุณสมบัติ form ของ HTML DOM Input Text


คุณสมบัติ form ของ HTML DOM Input Text ใช้สำหรับส่งคืนการอ้างอิงของฟอร์มที่มีช่องข้อความ input หากช่องข้อความอยู่นอกฟอร์มจะส่งคืน NULL คุณสมบัตินี้เป็น read-only

ไวยากรณ์

ไวยากรณ์สำหรับคุณสมบัติ form ของ input text:

textObject.form

ตัวอย่าง

มาดูตัวอย่างสำหรับคุณสมบัติ form ของ Input text:

<!DOCTYPE html> <html> <body> <h1>Input Text form Property</h1> <form id="NEW_FORM"> USERNAME: <input type="text" id="TEXT1"> </form> <p>ดึง id ของฟอร์มโดยคลิกปุ่มด้านล่าง</p> <button type="button" onclick="formId()">GET FORM</button> <p id="Sample"></p> <script>    function formId() {       var P=document.getElementById("TEXT1").form.id;       document.getElementById("Sample").innerHTML = "The id of the form containing the text field is: "+P ;    } </script> </body> </html>

ผลลัพธ์

จะได้ผลลัพธ์ดังนี้:

คุณสมบัติ form ของ HTML DOM Input Text

เมื่อคลิกปุ่ม GET FORM:

คุณสมบัติ form ของ HTML DOM Input Text