<script type="text/javascript">
<!--
var f = document.getElementById("f");

//获得select列表项数目
document.write(f.s.options.length);
document.write(f.s.length);

//当前选中项的下标(从0 开始)(有两种方法)
//如果选择了多项,则返回第一个选中项的下标
document.write(f.s.options.selectedIndex);
document.write(f.s.selectedIndex);

//检测某一项是否被选中
document.write(f.s.options[0].selected);

//获得某一项的值和文字
document.write(f.s.options[0].value);
document.write(f.s.options[1].text);

//删除某一项
f.s.options[1] = null;

//追加一项
f.s.options[f.s.options.length] = new Option("追加的text", "追加的value");

//更改一项
f.s.options[1] = new Option("更改的text", "更改的value");
//也可以直接设置该项的 text 和 value
//-->
</script>


//全选列表中的项
function SelectAllOption(list)
{
for (var i=0; i<list.options.length; i++)
{
list.options[i].selected = true;
}
}


//反选列表中的项 by aspxuexi.com asp学习网
function DeSelectOptions(list)
{
for (var i=0; i<list.options.length; i++)
{
list.options[i].selected = !list.options[i].selected;
}
}


//返回列表中选择项数目
function GetSelectedOptionsCnt(list)
{
var cnt = 0;
var i = 0;
for (i=0; i<list.options.length; i++)
{
if (list.options[i].selected)
{
cnt++;
}
}

return cnt;
}


//清空列表
function ClearList(list)
{
while (list.options.length > 0)
{
list.options[0] = null;
}
}


//删除列表选中项
//返回删除项的数量
function DelSelectedOptions(list)
{
var i = 0;
var deletedCnt = 0;
while (i < list.options.length)
{
if (list.options[i].selected)
{
list.options[i] = null;
deletedCnt++;
}
else
{
i++;
}
}

return deletedCnt;
}