使用javascript實現(xiàn)ListBox左右全選,單選,多選,全請
<html>
<head>
<meta http-equiv="Content-Type " content="text/html; charset=gb2312 ">
<title>list測試</title>
</head>
<body>
<div style="font-size: 10pt;">
注1:左右移動進行選取
<br />
<br />
注:本頁面僅在IE6/FireFox1.5下測試過。其它瀏覽器或其它版本未經(jīng)測試。
<br />
<hr />
</div>
<form name="frm">
<table>
<tr>
<td>
<select name="SrcSelect" size="6" style="font-size: 11pt; width: 160px; height: 160px"
multiple="multiple" ondblclick="moveLeftOrRight(document.frm.SrcSelect,document.frm.ObjSelect) ">
<option value="1">講師</option>
</select>
</td>
<td width="30px">
<input align="left" type="button" value="> " onclick="moveLeftOrRight(document.frm.SrcSelect,document.frm.ObjSelect) ">
<br>
<br>
<input align="left" type="button" value=" < " onclick="moveLeftOrRight(document.frm.ObjSelect,document.frm.SrcSelect) ">
</td>
<td>
<select name="ObjSelect" size="6" style="font-size: 11pt; width: 160px; height: 160px"
multiple="multiple" ondblclick="moveLeftOrRight(document.frm.ObjSelect,document.frm.SrcSelect) ">
<option value="2">教學(xué)管理員</option>
<option value="3">超級管理員</option>
</select>
</td>
</tr>
</table>
</form>
</body>
<script type="text/javascript" language="javascript">
//上移
function moveUp() {
var theObjOptions = document.frm.ObjSelect.options;
for (var i = 1; i < theObjOptions.length; i++) {
if (theObjOptions[i].selected && !theObjOptions[i - 1].selected) {
swapOptionProperties(theObjOptions[i], theObjOptions[i - 1]);
}
}
}
//下移
function moveDown() {
var theObjOptions = document.frm.ObjSelect.options;
for (var i = theObjOptions.length - 2; i > -1; i--) {
if (theObjOptions[i].selected && !theObjOptions[i + 1].selected) {
swapOptionProperties(theObjOptions[i], theObjOptions[i + 1]);
}
}
}
function swapOptionProperties(option1, option2) {
var tempStr = option1.value;
option1.value = option2.value;
option1.value = tempStr;
tempStr = option1.text;
option1.text = option2.text;
option2.text = tempStr;
tempStr = option1.selected;
option1.selected = option2.selected;
option2.selected = tempStr;
}
//列表框的位置移動
function moveLeftOrRight(fromObj, toObj) {
for (var i = 0; i < fromObj.length; i++) {
var srcOption = fromObj.options[i];
if (srcOption.selected) {
toObj.appendChild(srcOption);
i--;
}
}
}
</script>
相關(guān)文章
JavaScript實現(xiàn)html轉(zhuǎn)pdf的三種方法詳解
近期項目需要實現(xiàn)將?html?頁面轉(zhuǎn)換成?pdf?報告的需求,經(jīng)過一番調(diào)研以及結(jié)合過往經(jīng)驗,發(fā)現(xiàn)了三種技術(shù)方案,下面我們就來看看它們的具體實現(xiàn)步驟吧2024-02-02

詳解BootStrap中Affix控件的使用及保持布局的美觀的方法

如何設(shè)置一定時間內(nèi)只能發(fā)送一次請求

Dropzone.js實現(xiàn)文件拖拽上傳功能(附源碼下載)