Option form 屬性

定義和用法
form 屬性可返回對(duì)包含選項(xiàng)的表單的引用。
該屬性返回 form 對(duì)象。
語(yǔ)法
optionObject.form
瀏覽器支持
所有主要瀏覽器都支持 form 屬性
實(shí)例
實(shí)例
本例可返回下拉列表中所選的選項(xiàng)的所屬表單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>
嘗試一下 ?

更多建議: