js实现的左右选择框
2009-01-20 17:04
267 查看
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
sortitems = 1; // Automatically sort items within lists? (1 or 0)
function move(fbox,tbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options[i].selected && fbox.options[i].value != "") {
var no = new Option();
no.value = fbox.options[i].value;
no.text = fbox.options[i].text;
tbox.options[tbox.options.length] = no;
fbox.options[i].value = "";
fbox.options[i].text = "";
}
}
BumpUp(fbox);
if (sortitems) SortD(tbox);
}
function moveall(fbox,tbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options[i].value != "") {
var no = new Option();
no.value = fbox.options[i].value;
no.text = fbox.options[i].text;
tbox.options[tbox.options.length] = no;
fbox.options[i].value = "";
fbox.options[i].text = "";
}
}
BumpUp(fbox);
if (sortitems) SortD(tbox);
}
function BumpUp(box) {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].value == "") {
for(var j=i; j<box.options.length-1; j++) {
box.options[j].value = box.options[j+1].value;
box.options[j].text = box.options[j+1].text;
}
var ln = i;
break;
}
}
if(ln < box.options.length) {
box.options.length -= 1;
BumpUp(box);
}
}
function SortD(box) {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++) {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++) {
for(var y=(x+1); y<temp_opts.length; y++) {
if(temp_opts[x].text > temp_opts[y].text) {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
}
}
}
for(var i=0; i<box.options.length; i++) {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
}
}
// End -->
</script>
<form ACTION="" METHOD="POST">
<table border="0">
<tr>
<td><select multiple size="5" name="list1" style="width:250px">
<option value="11"> item 1.1 </option>
<option value="12"> item 1.2 </option>
<option value="13"> item 1.3 </option>
</select></td>
<td>
<input type="button" value=" > " onclick="move(this.form.list1,this.form.list2)" name="B1">
<input type="button" value=" < " onclick="move(this.form.list2,this.form.list1)" name="B2">
<input type="button" value=" >> " onclick="moveall(this.form.list1,this.form.list2)" name="B3">
<input type="button" value=" << " onclick="moveall(this.form.list2,this.form.list1)" name="B4">
</td>
<td><select multiple size="5" name="list2" style="width:250px">
<option value="21"> item 2.1 </option>
<option value="22"> item 2.2 </option>
<option value="23"> item 2.3 </option>
</select></td>
</tr>
</table>
</form>
<!-- Begin
sortitems = 1; // Automatically sort items within lists? (1 or 0)
function move(fbox,tbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options[i].selected && fbox.options[i].value != "") {
var no = new Option();
no.value = fbox.options[i].value;
no.text = fbox.options[i].text;
tbox.options[tbox.options.length] = no;
fbox.options[i].value = "";
fbox.options[i].text = "";
}
}
BumpUp(fbox);
if (sortitems) SortD(tbox);
}
function moveall(fbox,tbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options[i].value != "") {
var no = new Option();
no.value = fbox.options[i].value;
no.text = fbox.options[i].text;
tbox.options[tbox.options.length] = no;
fbox.options[i].value = "";
fbox.options[i].text = "";
}
}
BumpUp(fbox);
if (sortitems) SortD(tbox);
}
function BumpUp(box) {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].value == "") {
for(var j=i; j<box.options.length-1; j++) {
box.options[j].value = box.options[j+1].value;
box.options[j].text = box.options[j+1].text;
}
var ln = i;
break;
}
}
if(ln < box.options.length) {
box.options.length -= 1;
BumpUp(box);
}
}
function SortD(box) {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++) {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++) {
for(var y=(x+1); y<temp_opts.length; y++) {
if(temp_opts[x].text > temp_opts[y].text) {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
}
}
}
for(var i=0; i<box.options.length; i++) {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
}
}
// End -->
</script>
<form ACTION="" METHOD="POST">
<table border="0">
<tr>
<td><select multiple size="5" name="list1" style="width:250px">
<option value="11"> item 1.1 </option>
<option value="12"> item 1.2 </option>
<option value="13"> item 1.3 </option>
</select></td>
<td>
<input type="button" value=" > " onclick="move(this.form.list1,this.form.list2)" name="B1">
<input type="button" value=" < " onclick="move(this.form.list2,this.form.list1)" name="B2">
<input type="button" value=" >> " onclick="moveall(this.form.list1,this.form.list2)" name="B3">
<input type="button" value=" << " onclick="moveall(this.form.list2,this.form.list1)" name="B4">
</td>
<td><select multiple size="5" name="list2" style="width:250px">
<option value="21"> item 2.1 </option>
<option value="22"> item 2.2 </option>
<option value="23"> item 2.3 </option>
</select></td>
</tr>
</table>
</form>
相关文章推荐
- js实现的左右选择框
- js实现左右选择框
- jquery实现左右选择框
- js 实现菜单左右滚动显示示例介绍
- JS实现用键盘控制DIV上下左右+放大缩小与变色
- js扩展滚动窗口小插件实现文字左右上下滚动效果实例
- js实现炫酷的左右轮播图
- js实现图片点击左右轮播
- js实现图片点击左右轮播
- JS使用正则实现去掉字符串左右空格的方法
- jquery插件jquery.beforeafter.js实现左右拖拽分隔条对比图片的方法
- JS实现图片滚动(无缝、平滑、上下左右滚动)效果
- Jquery和纯JS实现轮播图(一)--左右切换式
- JS实现点击按钮图片左右切换、点击图片按钮出现下拉菜单
- 用js实现简单的点击左右运动
- js实现键盘的上下左右控制图片移动
- js实现移动端手指左右上下滑动翻页效果
- js实现左右轮播图效果
- Js实现上下左右无缝隙滚动代码 一
- js实现左右轮播效果