Home  >  Article  >  Web Front-end  >  Common methods for Javascript select drop-down box operations_Form special effects

Common methods for Javascript select drop-down box operations_Form special effects

WBOY
WBOYOriginal
2016-05-16 18:42:041007browse
Copy code The code is as follows:

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);
}
}
//Delete the specified The drop-down box
function RemoveDropDownList(id)
{
var ctl = document.getElementById(id);
if(ctl)
ctl.parentNode.removeChild(ctl);
}
//Add options to the drop-down box
function AddDDDLOption(id,text,value)
{
var ctl = document.getElementById(id);
if(ctl)
{
ctl.options[ctl.options.length] = new Option(text,value);
}
}
//Remove all options
function RemoveAllDDLOptions(id)
{
var ctl = document.getElementById(id);
if(ctl)
{
ctl.options.length=0;
}
}
//Delete Options for specifying index
function RemoveDDLOption(id,index)
{
var ctl=document.getElementById(id);
if(ctl && ctl.options[index])
{
ctl.options[index]=null;
}
}
//Get the value selected in the drop-down box
function GetDDLSelectedValue(id)
{
var ctl = document. getElementById(id);
if(ctl)
{
return ctl.options[ctl.selectedIndex].value;
}
}
//Get the text selected by the drop-down box
function GetDDLSelectedText(id)
{
var ctl = document.getElementById(id);
if(ctl)
{
return ctl.options[ctl.selectedIndex].text ;
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn