HTML DOM Checkbox form 屬性
定義和用法
form 屬性返回包含複選框的表單引用。
該屬性返回form 對象。
語法
checkboxObject.form
瀏覽器支持
所有主要瀏覽器都支持form 屬性
實例
實例
面的例子返回了該checkbox 所屬的表單的id:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
<input type="checkbox" id="myCheck">你喜歡夏天嗎?
</form>
<button type="button" onclick="displayResult()">顯示包含選擇框的表單ID</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
<input type="checkbox" id="myCheck">你喜歡夏天嗎?
</form>
<button type="button" onclick="displayResult()">顯示包含選擇框的表單ID</button>
</body>
</html>
嘗試一下»
Checkbox對象