form
Option form 属性
定义和用法
form 属性可返回对包含选项的表单的引用。
该属性返回 form 对象。
语法
optionObject.form
浏览器支持
所有主要浏览器都支持 form 属性
实例
本例可返回下拉列表中所选的选项的所属表单id:
<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("mySelect").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">Display id of container form</button>
</body>
</html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("mySelect").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">Display id of container form</button>
</body>
</html>