<script>
var provinceOp = new Array(PROVNUM);
provinceOp[0]=new Option("控儔","控儔");
provinceOp[1]=new Option("毞踩","毞踩");
provinceOp[2]=new Option("碩控","碩控");
provinceOp[3]=new Option("刓昹","刓昹");
provinceOp[4]=new Option("囀蟹嘉","囀蟹嘉");
provinceOp[5]=new Option("賽譴","賽譴");
provinceOp[6]=new Option("憚輿","憚輿");
provinceOp[7]=new Option("窪韓蔬","窪韓蔬");
provinceOp[8]=new Option("奻漆","奻漆");
</script>
var provinceOp = new Array(PROVNUM);
provinceOp[0]=new Option("控儔","控儔");
provinceOp[1]=new Option("毞踩","毞踩");
provinceOp[2]=new Option("碩控","碩控");
provinceOp[3]=new Option("刓昹","刓昹");
provinceOp[4]=new Option("囀蟹嘉","囀蟹嘉");
provinceOp[5]=new Option("賽譴","賽譴");
provinceOp[6]=new Option("憚輿","憚輿");
provinceOp[7]=new Option("窪韓蔬","窪韓蔬");
provinceOp[8]=new Option("奻漆","奻漆");
</script>
完全可以按照数组的方式来操作。
<option>aaaa</option>
<option>bbbb</option>
<option>cccc</option>
<option>dddd</option>
<option>eeee</option>
</select><script>
var aa=document.all.aa.innerText.split(" ");
for (var i=1; i<aa.length; i++)
alert("AA数组里第 "+i+" 个值是:"+aa[i]);
</script>
我准备去改名了,(足球-编程-崇拜梅花雨!)
我想alert select.options却不行,我想是不是options本身不是数组????
select.options上一种对象:Collections它能象Array那样操作,但不等同于Array
options: An array corresponding to options in a select object
in source order;
this array contains an entry for each option in a select
object(OPTION tab) in source order.Array: an Array is an ordered set of values associated with a
sigle variable name.若你会用Java,那么可从另一个角度解释,
options与Array的toString()方法不一样!
欢迎讨论。
如果你已经在用户端完成了许多的对象管理工作,你可能使用的是微软公司的Scripting.Dictionary ActiveX。然而,如果你象我一样需要更快速度和更好控制的话,你应该使用JavaScript来制作它。它不仅更快,而且你还可以通过用户化而让它更适合你的要求。由于我只需要一个管理工具,所以我只需进行一些添加和删除操作就可以了。我的管理有一些混乱,因此我希望能够通过使用用户自定义key来留住我的项目。 首先,我会定义我需要哪些功能。我知道我希望能够通过一个key来访问所有项目。我希望通过简单的方法来管理这些信息,就象这样:var var1 = Collection.Item("key").Value;这个很容易创建。我所需要的是一个项目对象来储存我的信息,它的属性是:“Value”。我会把所有的项目都存储在Collection对象中,因此我还需为我的项目对象添加另一个属性来帮助我了解这些项目的索引。这个属性被我叫作:“Index”。下面是我现在已经做好的(为了更加简捷,我不会加入错误处理的内容):function Item(pvThing) {
this.Value = pvThing;
this.Index = -1;
} 我可以添加更多的功能,但是就现在来说这些功能还不需要。我创建了用于存储信息的对象,现在我需要做的就是创建一个Collection class来存储收集的项目。我会把这些项目存储到“all”中去,然后我会添加另一个属性来存储key indexes,这个属性被我称之为“aall”。基于简便的原因,我会添加另一个被称作“length”的属性来存储项目的数目,具体如下:function Collection() {
this.all = [];
this.aall = {};
this.length = 0;
}为了往例子中的Collection添加项目,我需要一种专门的方法。我首先要选择一个能够描述这种方法的名称,比如“Add”。Add方式让我可以在新添加的项目上创建key。此外,我还希望限定添加的项目的类型。下面是这段程序:点击查看 现在我需要从collection中删除项目的办法,我称之为“Remove”。我希望不但在项目中、在索引值中也能在key中使用。Remove方式通过一系列检查来确定参数的类型。然后,删除那些通过所有测试的项目。最后,它会升级所有剩下项目的索引属性,并且还升级Collection.length的属性。 然后,我会使用项目方式来保留特殊的那些项目。我希望能够通过索引值或者key来保留那些项目。项目方式是一种自我解释的方式。如果参数是一个key,那么会基于这个key来返回项目。如果是索引值,那么会基于array index来返回项目。 最后,我会添加删除所有这些项目的方法。请参照内含程序代码中的RemoveAll方式。清楚this.all和this.aall,然后重新设置Collection.length。下面是完整的代码:点击查看 我发现这个程序代码在许多情况下都非常的有用,尤其是在我不希望使用Scripting.Dictionary组件的时候。总之,这是一种通过创建用户化解决方案来管理用户collections的办法。
完整代码
Wednesday, August 7 2002 4:14 PM function Item(pvThing) {
this.Value = pvThing;
this.Index = -1;
}function Collection() {
this.all = [];
this.aall = {};
this.length = 0;
this.Add = function (poItem, pvKey) {
if (typeof(poItem) == "object" && poItem.constructor == Item) {
var idx = this.all.push(poItem) - 1; // 'push' was added in IE 5.5
if (this.all[idx].Index = -1) {
this.all[idx].Index = idx;
}
if (typeof(pvKey) != "undefined") {
this.all[idx].Key = pvKey;
this.aall[pvKey] = this.all[idx];
}
this.length = this.all.length;
} else {
alert("Item must be an Item object.");
}
}
this.Remove = function (pvItem) {
if (typeof(pvItem) == "object" && pvItem.constructor == Item) {
for (var i = 0; i < this.all.length; i++) {
if (this.all[i] == pvItem) {
this.all.splice(i, 1);
if (typeof(this.all[i].Key) != "undefined") {
delete this.aall[this.all[i].Key] ;
}
break;
}
}
} else if (typeof(this.aall[pvItem]) != "undefined") {
this.all.splice(this.aall[pvItem].Index, 1); // 'splice'
was added in IE 5.5
delete this.aall[pvItem];
} else if (typeof(this.all[pvItem]) != "undefined") {
if (typeof(this.all[pvItem].Key) != "undefined") {
delete this.aall[this.all[pvItem].Key];
}
this.all.splice(pvItem, 1);
}
for (var i = 0; i < this.all.length; i++) {
this.all[i].Index = i;
}
this.length = this.all.length;
} this.Item = function (pvKeyOrIndex) {
if (typeof(this.aall[pvKeyOrIndex]) != "undefined") {
return this.aall[pvKeyOrIndex];
} else if (typeof(this.all[pvKeyOrIndex]) != "undefined") {
return this.all[pvKeyOrIndex];
}
} this.RemoveAll = function () {
this.all = [];
this.aall = {};
this.length = 0;
}}