js select多選列表傳值代碼
更新時(shí)間:2009年12月06日 16:49:12 作者:
select多選列表傳值,主要是讀取選中的值,然后傳遞到對(duì)面的select中,每個(gè)功能都是獨(dú)立的代碼。
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
js核心代碼
復(fù)制代碼 代碼如下:
/*移除左邊選中的列表項(xiàng)到右邊*/
function fMoveSelectedOptionsLeftToRight(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(!hasOptions(oLeft))
{
return;
}
if(oLeft.selectedIndex==-1)
{
oLeft.selectedIndex=0;
}
for(var i=0;i<oLeft.options.length;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);
}
/*移除左邊的所有列表項(xiàng)到右邊*/
function fMoveAllOptionsLeftToRight(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(!hasOptions(oLeft))
{
return;
}
for(var i=0;i<oLeft.options.length;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);
}
/*移除右邊選中的列表項(xiàng)到左邊*/
function fMoveSelectedOptionsRightToLeft(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(!hasOptions(oRight))
{
return;
}
if(oRight.selectedIndex==-1)
{
oRight.selectedIndex=0;
}
for(var i=0;i<oRight.options.length;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);
}
/*移除右邊的所有列表項(xiàng)到左邊*/
function fMoveAllOptionsRightToLeft(oLeft,oRight)
{
if(!(oLeft&&oRight))
{
return;
}
if(!hasOptions(oRight))
{
return;
}
for(var i=0;i<oRight.options.length;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);
}
/*清空select所有options*/
function clearAllOptions(oSelect)
{
if(oSelect)
{
var ops=oSelect.options;
while(ops.length>0)
{
oSelect.remove(ops.length-1);
}
}
}
/*清空select所有選中的options*/
function clearSelectedOptions(oSelect)
{
if(oSelect)
{
for(var i=0;i<oSelect.options.length;i++)
{
if(oSelect.options[i].selected)
{
oSelect.remove(i--);
}
}
}
}
/*判斷select是否有options*/
function hasOptions(oSelect)
{
if(oSelect)
{
return oSelect.options.length>0;
}
return false;
}
您可能感興趣的文章:
- js實(shí)現(xiàn)可輸入可選擇的select下拉框
- Angularjs實(shí)現(xiàn)帶查找篩選功能的select下拉框示例代碼
- JS組件Bootstrap Select2使用方法解析
- js自定義select下拉框美化特效
- angularjs 實(shí)現(xiàn)帶查找篩選功能的select下拉框?qū)嵗?/a>
- javascript Select標(biāo)記中options操作方法集合
- JS組件Bootstrap Select2使用方法詳解
- javascript操作select參考代碼
- js 操作select和option常用代碼整理
- JS獲取select-option-text_value的方法
- JS操作select下拉框動(dòng)態(tài)變動(dòng)(創(chuàng)建/刪除/獲取)
- js select option對(duì)象小結(jié)
- JavaScript實(shí)現(xiàn)的select點(diǎn)菜功能示例
相關(guān)文章
javascript在一段文字中的光標(biāo)處插入其他文字
javascript在一段文字中的光標(biāo)處插入其他文字...2007-08-08
javascript之文本框輸入四個(gè)數(shù)字自動(dòng)加空格的腳本
javascript之文本框輸入四個(gè)數(shù)字自動(dòng)加空格的腳本...2007-11-11
兼容Firefox和IE的onpropertychange事件oninput
onpropertychange能夠捕獲每次輸入值的變化。例如:對(duì)象的value值被改變時(shí),onpropertychange能夠捕獲每次改變,而onchange需要執(zhí)行某個(gè)事件才可以捕獲。2008-06-06
Js 載入時(shí)選中文字的實(shí)現(xiàn)代碼
Js 載入時(shí)選中文字的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-05-05

