HTML DOM 輸入複選框表單屬性
HTML DOM 輸入複選框表單屬性返回包含輸入複選框的表單。
語法
以下是語法 −
返回對form物件的引用
inputCheckboxObject.form
示例
我們來看一個 HTML DOM 輸入複選框表單屬性的示例 −
<!DOCTYPE html> <html> <head> <title>Student Details</title> </head> <body> <form id="Student-Form"> <div> <input type="text" name="fullName" placeholder="eg: John Doe"> Show Form ID: <input id="formID" type="checkbox" name="formID"> </div> </form> <button onclick="getFormID()">Get ID of form containing this Checkbox</button> <div id="showResult"></div> <script> function getFormID(){ var checkboxFilter = document.getElementById("formID"); var showResultDiv = document.getElementById("showResult"); if(checkboxFilter.checked == true){ showResultDiv.textContent = 'Form ID: ' + checkboxFilter.form.id; } else { showResultDiv.textContent = 'Check the checkbox'; } } </script> </body> </html>
輸出
將產生以下輸出 −
在選中“顯示錶單 ID”複選框之前 −
在選中“顯示錶單 ID”複選框之後 −
廣告