JavaScript之內部陣列

鍾超發表於2011-11-15

1、文件表單陣列

文件中所有表單,構成的陣列。


<html><head></head><body>

<form id="first"></form>

<form id="second"></form>

<form id="thrid"></form>

<script type="text/javascript"><!-- 或者<script language="javascript"> -->

var fs = document.forms;

for (i = 0; i < fs.length; ++i) {

alert(fs[i].id);

}

</script>

</body></html>



2、選擇列表的選項陣列


<html><head></head><body>

<form id="first">

<select name="object" onclick="test()">

<option value="china">中國</option>

<option value="us">美國</option>

<option value="uk">英國</option>

</select>

</form>

<script type="text/javascript"><!-- 或者<script language="javascript"> -->

var object = document.getElementById("object");

for (i = 0; i < object.options.length; ++i) {

alert(object.options[i].value + ", " + object.options[i].text);

}

</script>

</body></html>

相關文章