object.options.add(new Option(label,value))方法向集合里添加一项option对象;
object.options.remove(index)方法移除options集合中的指定项;
object.options(index)或options.item(index)可以通过索引获取options集合的指定项;
select标记还有一个属性为selectedIndex,通过它可能获取当前选择的option索引:object.selectedIndex
1.清空options集合
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->function optionsClear(object)
{
var length = object.options.length;
for(var i=length-1;i>=0;i--){
e.options.remove(i);
}
}
2.添加一项新option
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->function addOption(object)
{
object.add(new Option(label,value));
//使用options集合中最后一项获取焦点
object.selectedIndex = object.lentht-1;
}
3.删除options集合中指定的一项option
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->function removeOption(index)
{
if(index >= 0)
{
object.remove(index);
//使用options集合中最后一项获取焦点
object.selectedIndex = object.lentht-1;
}
}
4.获取当前选定的option的真实值value
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->function getCurrentOptionValue(index)
{
if(index >= 0)
return object(index).value;
}
5.获取当前选定的option的显示值label
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->function getCurrentOptionLabel(index)
{
if(index >= 0)
return object(index).text;
}
[@more@]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7558084/viewspace-1003476/
,如需转载,请注明出处,否则将追究法律责任。