js select多選列表傳值代碼
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
js核心代碼
/*移除左邊選中的列表項(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)文章
在第一個(gè)input框內(nèi)輸入內(nèi)容.textarea自動(dòng)得到第一個(gè)文件框的值的javascript代碼
在第一個(gè)input框內(nèi)輸入內(nèi)容.textarea自動(dòng)得到第一個(gè)文件框的值的javascript代碼...2007-04-04為radio類型的INPUT添加客戶端腳本(附加實(shí)現(xiàn)JS來禁用onClick事件思路代碼)
為radio類型的INPUT添加客戶端腳本(附加實(shí)現(xiàn)JS來禁用onClick事件思路代碼),需要的朋友可以參考下。2010-11-11在textarea中顯示html頁面的javascript代碼
在textarea中顯示html頁面的javascript代碼...2007-04-04關(guān)于表單的兩點(diǎn)交互體驗(yàn)改進(jìn)技巧
關(guān)于表單的兩點(diǎn)交互體驗(yàn)改進(jìn)技巧...2007-02-02用javascript實(shí)現(xiàn)改變TEXTAREA滾動(dòng)條和按鈕的顏色,以及怎樣讓滾動(dòng)條變得扁平
用javascript實(shí)現(xiàn)改變TEXTAREA滾動(dòng)條和按鈕的顏色,以及怎樣讓滾動(dòng)條變得扁平...2007-04-04js正則實(shí)現(xiàn)的密碼框簡(jiǎn)單制作,還可以替換成自己想用得符號(hào)
js正則實(shí)現(xiàn)的密碼框簡(jiǎn)單制作,還可以替換成自己想用得符號(hào)...2007-10-10