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>

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

输出

将产生以下输出 −

在选中“显示表单 ID”复选框之前 −

在选中“显示表单 ID”复选框之后 −

更新于: 2019年7月30日

131 次浏览

开启你的职业

通过完成课程获得认证

开始
广告