js select多選列表傳值代碼
更新時間:2009年12月06日 16:49:12 作者:
select多選列表傳值,主要是讀取選中的值,然后傳遞到對面的select中,每個功能都是獨立的代碼。
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
js核心代碼
復制代碼 代碼如下:
/*移除左邊選中的列表項到右邊*/
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);
}
/*移除左邊的所有列表項到右邊*/
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);
}
/*移除右邊選中的列表項到左邊*/
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);
}
/*移除右邊的所有列表項到左邊*/
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實現(xiàn)可輸入可選擇的select下拉框
- Angularjs實現(xiàn)帶查找篩選功能的select下拉框示例代碼
- JS組件Bootstrap Select2使用方法解析
- js自定義select下拉框美化特效
- angularjs 實現(xiàn)帶查找篩選功能的select下拉框實例
- javascript Select標記中options操作方法集合
- JS組件Bootstrap Select2使用方法詳解
- javascript操作select參考代碼
- js 操作select和option常用代碼整理
- JS獲取select-option-text_value的方法
- JS操作select下拉框動態(tài)變動(創(chuàng)建/刪除/獲取)
- js select option對象小結
- JavaScript實現(xiàn)的select點菜功能示例
相關文章
在第一個input框內輸入內容.textarea自動得到第一個文件框的值的javascript代碼
在第一個input框內輸入內容.textarea自動得到第一個文件框的值的javascript代碼...2007-04-04為radio類型的INPUT添加客戶端腳本(附加實現(xiàn)JS來禁用onClick事件思路代碼)
為radio類型的INPUT添加客戶端腳本(附加實現(xiàn)JS來禁用onClick事件思路代碼),需要的朋友可以參考下。2010-11-11在textarea中顯示html頁面的javascript代碼
在textarea中顯示html頁面的javascript代碼...2007-04-04用javascript實現(xiàn)改變TEXTAREA滾動條和按鈕的顏色,以及怎樣讓滾動條變得扁平
用javascript實現(xiàn)改變TEXTAREA滾動條和按鈕的顏色,以及怎樣讓滾動條變得扁平...2007-04-04js正則實現(xiàn)的密碼框簡單制作,還可以替換成自己想用得符號
js正則實現(xiàn)的密碼框簡單制作,還可以替換成自己想用得符號...2007-10-10