Javascript select下拉框操作常用方法
更新時(shí)間:2009年11月09日 16:58:02 作者:
Javascript操作下拉框的常用方法,在js與表單控制中,經(jīng)常用的到。
復(fù)制代碼 代碼如下:
function AddDropDownList(id,fatherCtl)
{
if(!document.getElementById(id))
{
var ddl = document.createElement('select');
ddl.setAttribute("id",id);
if(fatherCtl&&document.getElementById(fatherCtl))
document.getElementById(fatherCtl).appendChild(ddl);
else
document.body.appendChild(ddl);
}
}
//刪除指定的下拉框
function RemoveDropDownList(id)
{
var ctl = document.getElementById(id);
if(ctl)
ctl.parentNode.removeChild(ctl);
}
//給下拉框添加選項(xiàng)
function AddDDDLOption(id,text,value)
{
var ctl = document.getElementById(id);
if(ctl)
{
ctl.options[ctl.options.length] = new Option(text,value);
}
}
//刪除所有選項(xiàng)
function RemoveAllDDLOptions(id)
{
var ctl = document.getElementById(id);
if(ctl)
{
ctl.options.length=0;
}
}
//刪除指定索引的選項(xiàng)
function RemoveDDLOption(id,index)
{
var ctl=document.getElementById(id);
if(ctl && ctl.options[index])
{
ctl.options[index]=null;
}
}
//獲取下拉框選擇的值
function GetDDLSelectedValue(id)
{
var ctl = document.getElementById(id);
if(ctl)
{
return ctl.options[ctl.selectedIndex].value;
}
}
//獲取下拉框選擇的文本
function GetDDLSelectedText(id)
{
var ctl = document.getElementById(id);
if(ctl)
{
return ctl.options[ctl.selectedIndex].text;
}
}
您可能感興趣的文章:
- js實(shí)現(xiàn)Select下拉框具有輸入功能的方法
- JS操作select下拉框動(dòng)態(tài)變動(dòng)(創(chuàng)建/刪除/獲取)
- JavaScript實(shí)現(xiàn)將數(shù)組數(shù)據(jù)添加到Select下拉框的方法
- JS Select下拉框(支持輸入模糊查詢)
- javascript中select下拉框的用法總結(jié)
- JavaScript實(shí)現(xiàn)向select下拉框中添加和刪除元素的方法
- JavaScript實(shí)現(xiàn)兩個(gè)select下拉框選項(xiàng)左移右移
- js實(shí)現(xiàn)可輸入可選擇的select下拉框
- jquery及原生js獲取select下拉框選中的值示例
- JavaScript實(shí)現(xiàn)獲取select下拉框中第一個(gè)值的方法
相關(guān)文章
JavaScript Select和Option列表元素上下左右移動(dòng)
支持一次選中多項(xiàng)在左右列表中來(lái)回移動(dòng)2008-12-12
FileUpload 控件 禁止手動(dòng)輸入或粘貼的實(shí)現(xiàn)代碼
FileUpload 控件 禁止手動(dòng)輸入或粘貼的實(shí)現(xiàn)代碼,經(jīng)常用于比較安全無(wú)誤的輸入,例如身份證號(hào)碼,密碼,銀行賬戶等。2010-04-04
checkbox 多選框 聯(lián)動(dòng)實(shí)現(xiàn)代碼
對(duì)于checkbox 多選的聯(lián)動(dòng)效果,是個(gè)不錯(cuò)的思路,附代碼2008-10-10
用javascript實(shí)現(xiàn)文本框和"選擇"按扭之間的間距
用javascript實(shí)現(xiàn)文本框和"選擇"按扭之間的間距...2007-07-07
用javascript判斷輸入數(shù)據(jù)是否貨幣并自動(dòng)添加¥符號(hào)的代碼
用javascript判斷輸入數(shù)據(jù)是否貨幣并自動(dòng)添加¥符號(hào)的代碼...2007-08-08
同一個(gè)表單 根據(jù)要求遞交到不同頁(yè)面的實(shí)現(xiàn)方法小結(jié)
同一個(gè)表單 根據(jù)要求遞交到不同頁(yè)面的實(shí)現(xiàn)方法,就是好多網(wǎng)站,可以百度一個(gè)表單可以搜索音樂,圖片等2009-08-08
js限制文本框?yàn)檎麛?shù)和貨幣的函數(shù)代碼
js限制文本框?yàn)檎麛?shù)和貨幣的函數(shù)代碼,方便一些數(shù)據(jù)庫(kù)字段的控制。2010-10-10

