Home >Web Front-end >JS Tutorial >js select multi-select list value passing code_form special effects

js select multi-select list value passing code_form special effects

WBOY
WBOYOriginal
2016-05-16 18:40:061038browse

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute ]


js core code
Copy code The code is as follows:

/*Remove the selected list item on the left to the right* /
function fMoveSelectedOptionsLeftToRight(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(!hasOptions(oLeft))
{
return;
}
if(oLeft.selectedIndex==-1)
{
oLeft.selectedIndex=0;
}
for(var i= 0;i{
if(oLeft.options[i].selected)
{
var oOption = document.createElement("OPTION");
oOption.setAttribute("text",oLeft.options[i].text);
oOption.setAttribute("value",oLeft.options[i].value);
oRight.add(oOption) ;
}
}
clearSelectedOptions(oLeft);
}
/*Remove all list items on the left to the right*/
function fMoveAllOptionsLeftToRight(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(!hasOptions(oLeft))
{
return;
}
for(var i=0;i{
var oOption = document.createElement("OPTION");
oOption.setAttribute("text",oLeft. options[i].text);
oOption.setAttribute("value",oLeft.options[i].value);
oRight.add(oOption);
}
clearAllOptions(oLeft) ;
}
/*Remove the selected list item on the right to the left*/
function fMoveSelectedOptionsRightToLeft(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(!hasOptions(oRight))
{
return;
}
if(oRight.selectedIndex==-1)
{
oRight.selectedIndex=0;
}
for(var i=0;i{
if(oRight.options[i].selected)
{
var oOption = document.createElement("OPTION");
oOption.setAttribute("text",oRight.options[i].text);
oOption.setAttribute("value" ,oRight.options[i].value);
oLeft.add(oOption);
}
}
clearSelectedOptions(oRight);
}
/*Remove the right one All list items to the left*/
function fMoveAllOptionsRightToLeft(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(! hasOptions(oRight))
{
return;
}
for(var i=0;i{
var oOption = document. createElement("OPTION");
oOption.setAttribute("text",oRight.options[i].text);
oOption.setAttribute("value",oRight.options[i].value);
oLeft.add(oOption);
}
clearAllOptions(oRight);
}
/*Clear all select options*/
function clearAllOptions(oSelect)
{
if(oSelect)
{
var ops=oSelect.options;
while(ops.length>0)
{
oSelect.remove(ops.length-1);
}
}
}
/*Clear all selected options*/
function clearSelectedOptions(oSelect)
{
if(oSelect)
{
for (var i=0;i{
if(oSelect.options[i].selected)
{
oSelect.remove(i--);
}
}
}
}
/*Judge whether select has options*/
function hasOptions(oSelect)
{
if(oSelect)
{
return oSelect.options.length>0;
}
return false;
}
">
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
Previous article:javascript mixed constructor and prototype method, dynamic prototype method_js object-orientedNext article:javascript mixed constructor and prototype method, dynamic prototype method_js object-oriented

Related articles

See more