<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;
}