国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
javascript對(duì)下拉列表框(select)的操作

 

<form id="f"> 
<select size="1" name="s"> 
<option value="www.dwww.cn">設(shè)計(jì)家園</option> 
<option value="baidu.com">百度</option> 
</select> 
</form>

---------------------------------------------------------------------------

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

//獲得select列表項(xiàng)數(shù)目 
document.write(f.s.options.length); 
document.write(f.s.length);

//當(dāng)前選中項(xiàng)的下標(biāo)(從0 開始)(有兩種方法) 
//如果選擇了多項(xiàng),則返回第一個(gè)選中項(xiàng)的下標(biāo) 
document.write(f.s.options.selectedIndex); 
document.write(f.s.selectedIndex);

//檢測(cè)某一項(xiàng)是否被選中 
document.write(f.s.options[0].selected);

//獲得某一項(xiàng)的值和文字 
document.write(f.s.options[0].value); 
document.write(f.s.options[1].text);

//刪除某一項(xiàng) 
f.s.options[1] = null;

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

//更改一項(xiàng) 
f.s.options[1] = new Option("更改的text", "更改的value"); 
//也可以直接設(shè)置該項(xiàng)的 text 和 value 
//--> 
</script>


//全選列表中的項(xiàng) 
function SelectAllOption(list) 

for (var i=0; i<list.options.length; i++) 

list.options[i].selected = true; 

}


//反選列表中的項(xiàng) 
function DeSelectOptions(list) 

for (var i=0; i<list.options.length; i++) 

list.options[i].selected = !list.options[i].selected; 

}


//返回列表中選擇項(xiàng)數(shù)目 
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; 

}


//刪除列表選中項(xiàng) 
//返回刪除項(xiàng)的數(shù)量 
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; 

//此函數(shù)查找相應(yīng)的項(xiàng)是否存在 
//repeatCheck是否進(jìn)行重復(fù)性檢查 
//若為"v",按值進(jìn)行重復(fù)值檢查 
//若為"t",按文字進(jìn)行重復(fù)值檢查 
//若為"vt",按值和文字進(jìn)行重復(fù)值檢查 
//其它值,不進(jìn)行重復(fù)性檢查,返回false 
function OptionExists(list, optText, optValue, repeatCheck) 

var i = 0; 
var find = false;

if (repeatCheck == "v") 

//按值進(jìn)行重復(fù)值檢查 
for (i=0; i<list.options.length; i++) 

if (list.options[i].value == optValue) 

find = true; 
break; 



else if (repeatCheck == "t") 

//按文字進(jìn)行重復(fù)檢查 
for (i=0; i<list.options.length; i++) 

if (list.options[i].text == optText) 

find = true; 
break; 



else if (repeatCheck == "vt") 

//按值和文字進(jìn)行重復(fù)檢查 
for (i=0; i<list.options.length; i++) 

if ((list.options[i].value == optValue) && (list.options[i].text == optText)) 

find = true; 
break; 


}

return find; 
}


//向列表中追加一個(gè)項(xiàng) 
//list 是要追加的列表 
//optText 和 optValue 分別表示項(xiàng)的文字和值 
//repeatCheck 是否進(jìn)行重復(fù)性檢查,參見 OptionExists 
//添加成功返回 true,失敗返回 false 
function AppendOption(list, optText, optValue, repeatCheck) 

if (!OptionExists(list, optText, optValue, repeatCheck)) 

list.options[list.options.length] = new Option(optText, optValue); 
return true; 

else 

return false; 

}


//插入項(xiàng) 
//index 插入位置,當(dāng)插入位置 >= 列表現(xiàn)有項(xiàng)數(shù)量時(shí),其作用相當(dāng)于不進(jìn)行重復(fù)檢查的追加項(xiàng) 
//optText 和 optValue 分別表示項(xiàng)的文字和值 
function InsertOption(list, index, optText, optValue) 

var i = 0; 
for (i=list.options.length; i>index; i--) 

list.options[i] = new Option(list.options[i-1].text, list.options[i-1].value); 
}

list.options[index] = new Option(optText, optValue); 

//將一個(gè)列表中的項(xiàng)導(dǎo)到另一個(gè)列表中 
//repeatCheck是否進(jìn)行重復(fù)性檢查,參見OptionExists 
//deleteSource項(xiàng)導(dǎo)到目標(biāo)后,是否刪除源列表中的項(xiàng) 
//返回影響的項(xiàng)數(shù)量 
function ListToList(sList, dList, repeatCheck, deleteSource) 

//所影響的行數(shù) 
var lines = 0; 
var i = 0; 
while (i<sList.options.length) 

if (sList.options[i].selected && AppendOption(dList, sList.options[i].text, sList.options[i].value, repeatCheck)) 

//添加成功 
lines++; 
if (deleteSource) 

//刪除源列表中的項(xiàng) 
sList.options[i] = null; 

else 

i++; 


else 

i++; 

}

return lines; 
}


//列表中選中項(xiàng)上移 
function MoveSelectedOptionsUp(list) 

var i = 0; 
var value = ""; 
var text = ""; 
for (i=0; i<(list.options.length-1); i++) 

if (!list.options[i].selected && list.options[i+1].selected) 

value = list.options[i].value; 
text = list.options[i].text; 
list.options[i] = new Option(list.options[i+1].text, list.options[i+1].value); 
list.options[i].selected = true; 
list.options[i+1] = new Option(text, value); 


}


//列表中選中項(xiàng)下移 
function MoveSelectedOptionsDown(list) 

var i = 0; 
var value = ""; 
var text = ""; 
for (i=list.options.length-1; i>0; i--) 
{


if (!list.options[i].selected && list.options[i-1].selected) 

value = list.options[i].value; 
text = list.options[i].text; 
list.options[i] = new Option(list.options[i-1].text, list.options[i-1].value); 
list.options[i].selected = true; 
list.options[i-1] = new Option(text, value); 


}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
動(dòng)態(tài)生成select選項(xiàng)全接觸
左右表格中內(nèi)容可調(diào)換的代碼
一個(gè)原創(chuàng)的基于Ajax的通用(組合)查詢(續(xù)) - 冰戈 - 博客園
javascript 實(shí)現(xiàn)左移右移上移下移(廈門_小魚兒_^1^)
Javascript - Select操作大集合
Javascript操作Select和Option
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服