Javascript select下拉框操作常用方法
作者:bea
代码如下: function AddDropDownList(id,fatherCtl) { if(!document.getElementById(id)) { var ddl = document.createElement('select'); ddl.setAttribute("id",id); if(fatherCtl&&document.getElementById(fatherCtl)) document.getElementB
代码如下:
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);
}
//给下拉框添加选项
function AddDDDLOption(id,text,value)
{
var ctl = document.getElementById(id);
if(ctl)
{
ctl.options[ctl.options.length] = new Option(text,value);
}
}
//删除所有选项
function RemoveAllDDLOptions(id)
{
var ctl = document.getElementById(id);
if(ctl)
{
ctl.options.length=0;
}
}
//删除指定索引的选项
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;
}
}
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- ASP中进行HTML数据及JS数据编码函数
- javascript 日期常用的方法
- Jquery在IE7下无法使用 $.ajax解决方法
- jQuery 白痴级入门教程
- Javascript 解疑
- 不一样的文字闪烁 轮番闪烁
- JS旋转的彩色文字轮转特效
- 文字来回上下移动或跳动的代码
- jquery 输入框数字限制插件
- 通过隐藏option实现select的联动效果
- javascript实现的鼠标悬停时动态翻滚的导航条
- Js 实现表格隔行换色一例
- Javascript实现的CSS代码高亮显示
- Riot.js 快速的JavaScript单元测试框架
- asp.net HttpHandler实现图片防盗链
- 为javascript添加String.Format方法
- prototype 中文参数乱码解决方案
- javascript currying返回函数的函数
- jQuery 常见学习网站与参考书