options Collection Internet Development Index --------------------------------------------------------------------------------Retrieves a collection of the option objects in a select object.Syntax[ oColl = ] SELECT.options
[ oObject = ] SELECT.options(vIndex [, iSubIndex]) Possible ValuesoColl Array of option objects.
oObject Reference to an individual item in the array of elements contained by the object.
vIndex Required. Integer or string that specifies the element or collection to retrieve. If this parameter is an integer, the method returns the element in the collection at the given position, where the first element has value 0, the second has 1, and so on. If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements.
iSubIndex Optional. Position of an element to retrieve. This parameter is used when vIndex is a string. The method uses the string to construct a collection of all elements that have a name or id property equal to the string, and then retrieves from this collection the element at the position specified by iSubIndex. Members TableThe following table lists the members exposed by the options object. Click a tab on the left to choose the type of member you want to view. Methods
SHOW:
Attributes/Properties
Methods
Property Description
length Sets or retrieves the number of objects in a collection. Method Description
add Adds an element to the areas, controlRange, or options collection.
item Retrieves an object from the all collection or various other collections.
namedItem Retrieves an object or a collection from the specified collection.
remove Removes an element from the collection.
tags Retrieves a collection of objects that have the specified HTML tag name.
urns Retrieves a collection of all objects to which a specified behavior is attached.
Attributes/PropertiesMethodsResTo delete an option object from a select object, assign the option object a null value. This compresses the array.If duplicate identifiers are found, a collection of those items is returned. Collections of duplicates must be referenced subsequently by ordinal position.ExampleThis example shows how to display the text and values of all option objects in the first select object in the document. HideExamplevar coll = document.all.tags("SELECT");
if (coll.length>0) {
for (i=0; i< coll(0).options.length; i++)
alert("Element " + i + " is " + coll(0).options(i).text +
" and has the value " + coll(0).options(i).value);
}
[ oObject = ] SELECT.options(vIndex [, iSubIndex]) Possible ValuesoColl Array of option objects.
oObject Reference to an individual item in the array of elements contained by the object.
vIndex Required. Integer or string that specifies the element or collection to retrieve. If this parameter is an integer, the method returns the element in the collection at the given position, where the first element has value 0, the second has 1, and so on. If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements.
iSubIndex Optional. Position of an element to retrieve. This parameter is used when vIndex is a string. The method uses the string to construct a collection of all elements that have a name or id property equal to the string, and then retrieves from this collection the element at the position specified by iSubIndex. Members TableThe following table lists the members exposed by the options object. Click a tab on the left to choose the type of member you want to view. Methods
SHOW:
Attributes/Properties
Methods
Property Description
length Sets or retrieves the number of objects in a collection. Method Description
add Adds an element to the areas, controlRange, or options collection.
item Retrieves an object from the all collection or various other collections.
namedItem Retrieves an object or a collection from the specified collection.
remove Removes an element from the collection.
tags Retrieves a collection of objects that have the specified HTML tag name.
urns Retrieves a collection of all objects to which a specified behavior is attached.
Attributes/PropertiesMethodsResTo delete an option object from a select object, assign the option object a null value. This compresses the array.If duplicate identifiers are found, a collection of those items is returned. Collections of duplicates must be referenced subsequently by ordinal position.ExampleThis example shows how to display the text and values of all option objects in the first select object in the document. HideExamplevar coll = document.all.tags("SELECT");
if (coll.length>0) {
for (i=0; i< coll(0).options.length; i++)
alert("Element " + i + " is " + coll(0).options(i).text +
" and has the value " + coll(0).options(i).value);
}
<tr>
<td>City</td>
<td>
<select name=city onchange="document.all.country.value=this.options[this.selectedIndex].country;">
<option value="" country=""></option>
<option value="1" country="china">beijin</option>
<option value="2" country="usa">newyork</option>
</td>
<td>Country</td>
<td><input name=country readOnly></td>
</tr>
</table>
<option value = "">请选择</option>
<option value = "北京">中国</option>
<option value = "纽约">美国</option>
</select>
<select name = "secondSelect">
<option value = "">请选择</option>
</select>
<script language = 'javascript'>
onchangevalue = function()
{
var newOption = new Option();
var selectedIndexvalue = document.all.firstSelect.selectedIndex;
newOption.text = document.all.firstSelect.options[selectedIndexvalue].value;
newOption.value = document.all.firstSelect.options[selectedIndexvalue].value;
document.all.secondSelect.length =0;
document.all.secondSelect.options.add(newOption);
}
</script>
function fnc(){
re_name.value=r0.options[r0.selectedIndex].text
}function fncAdd(){
var txt=document.all.re_name.value;
if (txt.length>0){
var op = document.createElement("OPTION");
r0.options.add(op);
op.innerHTML = txt;
}
}
</script><input type=text id=re_name style="width:100px;height:20px;font-size:10pt;"><span style="width:2px;border:0px;">
<select id="r0" style="margin-left:-100px;width:118px;" onChange="fnc();">
<option>111111</option>
<option>222222</option>
<option>333333</option> </select>
</span>
表述2: 回复人: vc8850() ( ) 信誉:100 2005-07-28 14:12:00 得分: 0 两种表述,
是完全不一样的意思。为什么会出现这样的情况??????
捊须沉思中
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JK:支持民族工业,尽量少买X货</title>
</head>
<script language=javascript>var provinceArray=new Array();
provinceArray[0]=new Array();
provinceArray[0].countryCode="cn";
provinceArray[0].provinceCode="湖南";
provinceArray[0].provinceName="湖南";
provinceArray[1]=new Array();
provinceArray[1].countryCode="cn";
provinceArray[1].provinceCode="江西";
provinceArray[1].provinceName="江西";
provinceArray[2]=new Array();
provinceArray[2].countryCode="cn";
provinceArray[2].provinceCode="广东";
provinceArray[2].provinceName="广东";
provinceArray[3]=new Array();
provinceArray[3].countryCode="usa";
provinceArray[3].provinceCode="Washington";
provinceArray[3].provinceName="Washington";
provinceArray[4]=new Array();
provinceArray[4].countryCode="usa";
provinceArray[4].provinceCode="California";
provinceArray[4].provinceName="California";var cityArray=new Array();
cityArray[0]=new Array();
cityArray[0].countryCode="cn";
cityArray[0].provinceCode="湖南";
cityArray[0].cityCode="860731";
cityArray[0].cityName="长沙";
cityArray[1]=new Array();
cityArray[1].countryCode="cn";
cityArray[1].provinceCode="广东";
cityArray[1].cityCode="860755";
cityArray[1].cityName="深圳";
cityArray[2]=new Array();
cityArray[2].countryCode="cn";
cityArray[2].provinceCode="广东";
cityArray[2].cityCode="86020";
cityArray[2].cityName="广州";
cityArray[3]=new Array();
cityArray[3].countryCode="usa";
cityArray[3].provinceCode="California";
cityArray[3].cityCode="10005";
cityArray[3].cityName="Sacramento";
function countryChangeFun()
{
var countryCodeObj=document.frm.countryCode;
document.frm.countryName.value=countryCodeObj.options[countryCodeObj.selectedIndex].countryName;
var provinceCodeObj=document.frm.provinceCode;
provinceCodeObj.options.length=1;
provinceChangeFun();
for(var i=0;i<provinceArray.length;i++)
{
if(provinceArray[i].countryCode==countryCodeObj.value)
{
var tempOption=new Option(provinceArray[i].provinceName,provinceArray[i].provinceCode);
tempOption.provinceName=provinceArray[i].provinceName;
provinceCodeObj.options[provinceCodeObj.length]=tempOption;
}
}
}function provinceChangeFun()
{
var countryCodeObj=document.frm.countryCode;
var provinceCodeObj=document.frm.provinceCode;
if(provinceCodeObj.selectedIndex<0) provinceCodeObj.selectedIndex=0;
document.frm.provinceName.value=provinceCodeObj.options[provinceCodeObj.selectedIndex].provinceName;
var cityCodeObj=document.frm.cityCode;
cityCodeObj.options.length=1;
cityChangeFun();
if(provinceCodeObj.value=="") return ; for(var i=0;i<cityArray.length;i++)
{
if(cityArray[i].provinceCode==provinceCodeObj.value && cityArray[i].countryCode==countryCodeObj.value)
{
var tempOption=new Option(cityArray[i].cityName,cityArray[i].cityCode);
tempOption.cityName=cityArray[i].cityName;
cityCodeObj.options[cityCodeObj.length]=tempOption;
}
}}function cityChangeFun()
{
var cityCodeObj=document.frm.cityCode;
if(cityCodeObj.selectedIndex<0) cityCodeObj.selectedIndex=0;
document.frm.cityName.value=cityCodeObj.options[cityCodeObj.selectedIndex].cityName;}//以下代码的目的是:前进后退到本页面时能保存上次输入的值
window.onbeforeunload = function()
{
document.frm.defaultProvinceCode.value=document.frm.provinceCode.value;
document.frm.defaultCityCode.value=document.frm.cityCode.value;
}window.onload = function()
{
countryChangeFun();
document.frm.provinceCode.value=document.frm.defaultProvinceCode.value;
provinceChangeFun();
document.frm.cityCode.value=document.frm.defaultCityCode.value;
cityChangeFun();
}
</script><body>
<form name=frm>
Country:
<select name=countryCode style="width:120" onchange="countryChangeFun();">
<option value="" countryName=""></option>
<option value="cn" countryName="China">China</option>
<option value="usa" countryName="America">America</option>
</select>
<input name=countryName><br>
Province
<select name=provinceCode style="width:120" onchange="provinceChangeFun();">
<option value="" provinceName=""></option>
</select>
<input name=provinceName>
<input type=hidden name=defaultProvinceCode value="">
<br>
City
<select name=cityCode style="width:120" onchange="cityChangeFun();">
<option value="" cityName=""></option>
</select>
<input name=cityName>
<input type=hidden name=defaultCityCode value=""></form>
<a href="about:blank">Link to other page to test "History Back".</a></body></html>