成长手删代码40-listbox js操作上下左右移动.txt
2009-08-05 12:03
435 查看
<script type ="text/javascript">
function imgRight()
{
var ddlRight=document.getElementById ("LBRight");
var ddlLeft=document.getElementById ("LBLeft");
var count = 0;
for(var i=0;i<ddlLeft.length;i++)
{
count = 0;
if(ddlLeft[i].selected)
{
//查ddlRight在右边是否存在要加的项,如果存在,提示,不加
if(ddlRight.length==0)
{
ddlRight.options.add(new Option(ddlLeft[i].text,ddlLeft[i].value));
document.getElementById ("hiddenLBRightValue").value+=ddlLeft[i].value+","
}
else
{
for(var intRight=0;intRight<ddlRight.length;intRight++)
{
if(ddlRight[intRight].text==ddlLeft[i].text)
{
count++;
}
}
if(count==0)
{
ddlRight.options.add(new Option(ddlLeft[i].text,ddlLeft[i].value));
document.getElementById ("hiddenLBRightValue").value+=ddlLeft[i].value+","
}
}
}
}
}
function imgLeft()
{
var ddlRight=document.getElementById ("LBRight");
for(var i=0;i<ddlRight.length;i++)
{
if(ddlRight[i].selected)
{
ddlRight.remove(ddlRight.selectedIndex);
i--;
}
}
}
function imgUp()
{
var ddlRight=document.getElementById ("LBRight");
var count=0;
if(ddlRight.length!=0)
{
for(var i=0;i<ddlRight.length;i++)
{
if(ddlRight.selectedIndex!=0)
{
if(ddlRight[i].selected)
{
count++;
}
}
else
{
return ;
}
}
if(count!=0)//选中的不是第一项
{
if(ddlRight.selectedIndex<=ddlRight.length-1)
{
//ddlRight.options(ddlRight.selectedIndex).swapNode(ddlRight.options(ddlRight.selectedIndex-1));
var tempSelect=document.createElement ("option");
tempSelect.text=ddlRight.options[ddlRight.selectedIndex].text;
tempSelect.value=ddlRight.options[ddlRight.selectedIndex].value;
ddlRight.options[ddlRight.selectedIndex].text=ddlRight.options[ddlRight.selectedIndex-1].text;
ddlRight.options[ddlRight.selectedIndex].value=ddlRight.options[ddlRight.selectedIndex-1].value;
ddlRight.options[ddlRight.selectedIndex-1].text=tempSelect.text;
ddlRight.options[ddlRight.selectedIndex-1].value=tempSelect.value;
ddlRight.selectedIndex=ddlRight.selectedIndex-1;
}
}
else
{
alert("请先选择要上移的项");
}
}
else
{
alert("该列表中没有数据");
}
}
function imgDown()
{
var ddlRight=document.getElementById ("LBRight");
var count=0;
if(ddlRight.length!=0)
{
for(var i=0;i<ddlRight.length;i++)
{
if(ddlRight.selectedIndex!=ddlRight.length-1)
{
if(ddlRight[i].selected)
{
count++;
}
}
else
{
return ;
}
}
if(count!=0)//选中的不是第一项
{
if(ddlRight.selectedIndex<=ddlRight.length-1)
{
//ddlRight.options(ddlRight.selectedIndex).swapNode(ddlRight.options(ddlRight.selectedIndex-1));
var tempSelect=document.createElement ("option");
tempSelect.text=ddlRight.options[ddlRight.selectedIndex].text;
tempSelect.value=ddlRight.options[ddlRight.selectedIndex].value;
ddlRight.options[ddlRight.selectedIndex].text=ddlRight.options[ddlRight.selectedIndex+1].text;
ddlRight.options[ddlRight.selectedIndex].value=ddlRight.options[ddlRight.selectedIndex+1].value;
ddlRight.options[ddlRight.selectedIndex+1].text=tempSelect.text;
ddlRight.options[ddlRight.selectedIndex+1].value=tempSelect.value;
ddlRight.selectedIndex=ddlRight.selectedIndex+1;
}
}
else
{
alert("请先选择要上移的项");
}
}
else
{
alert("该列表中没有数据");
}
}
function imgRight()
{
var ddlRight=document.getElementById ("LBRight");
var ddlLeft=document.getElementById ("LBLeft");
var count = 0;
for(var i=0;i<ddlLeft.length;i++)
{
count = 0;
if(ddlLeft[i].selected)
{
//查ddlRight在右边是否存在要加的项,如果存在,提示,不加
if(ddlRight.length==0)
{
ddlRight.options.add(new Option(ddlLeft[i].text,ddlLeft[i].value));
document.getElementById ("hiddenLBRightValue").value+=ddlLeft[i].value+","
}
else
{
for(var intRight=0;intRight<ddlRight.length;intRight++)
{
if(ddlRight[intRight].text==ddlLeft[i].text)
{
count++;
}
}
if(count==0)
{
ddlRight.options.add(new Option(ddlLeft[i].text,ddlLeft[i].value));
document.getElementById ("hiddenLBRightValue").value+=ddlLeft[i].value+","
}
}
}
}
}
function imgLeft()
{
var ddlRight=document.getElementById ("LBRight");
for(var i=0;i<ddlRight.length;i++)
{
if(ddlRight[i].selected)
{
ddlRight.remove(ddlRight.selectedIndex);
i--;
}
}
}
function imgUp()
{
var ddlRight=document.getElementById ("LBRight");
var count=0;
if(ddlRight.length!=0)
{
for(var i=0;i<ddlRight.length;i++)
{
if(ddlRight.selectedIndex!=0)
{
if(ddlRight[i].selected)
{
count++;
}
}
else
{
return ;
}
}
if(count!=0)//选中的不是第一项
{
if(ddlRight.selectedIndex<=ddlRight.length-1)
{
//ddlRight.options(ddlRight.selectedIndex).swapNode(ddlRight.options(ddlRight.selectedIndex-1));
var tempSelect=document.createElement ("option");
tempSelect.text=ddlRight.options[ddlRight.selectedIndex].text;
tempSelect.value=ddlRight.options[ddlRight.selectedIndex].value;
ddlRight.options[ddlRight.selectedIndex].text=ddlRight.options[ddlRight.selectedIndex-1].text;
ddlRight.options[ddlRight.selectedIndex].value=ddlRight.options[ddlRight.selectedIndex-1].value;
ddlRight.options[ddlRight.selectedIndex-1].text=tempSelect.text;
ddlRight.options[ddlRight.selectedIndex-1].value=tempSelect.value;
ddlRight.selectedIndex=ddlRight.selectedIndex-1;
}
}
else
{
alert("请先选择要上移的项");
}
}
else
{
alert("该列表中没有数据");
}
}
function imgDown()
{
var ddlRight=document.getElementById ("LBRight");
var count=0;
if(ddlRight.length!=0)
{
for(var i=0;i<ddlRight.length;i++)
{
if(ddlRight.selectedIndex!=ddlRight.length-1)
{
if(ddlRight[i].selected)
{
count++;
}
}
else
{
return ;
}
}
if(count!=0)//选中的不是第一项
{
if(ddlRight.selectedIndex<=ddlRight.length-1)
{
//ddlRight.options(ddlRight.selectedIndex).swapNode(ddlRight.options(ddlRight.selectedIndex-1));
var tempSelect=document.createElement ("option");
tempSelect.text=ddlRight.options[ddlRight.selectedIndex].text;
tempSelect.value=ddlRight.options[ddlRight.selectedIndex].value;
ddlRight.options[ddlRight.selectedIndex].text=ddlRight.options[ddlRight.selectedIndex+1].text;
ddlRight.options[ddlRight.selectedIndex].value=ddlRight.options[ddlRight.selectedIndex+1].value;
ddlRight.options[ddlRight.selectedIndex+1].text=tempSelect.text;
ddlRight.options[ddlRight.selectedIndex+1].value=tempSelect.value;
ddlRight.selectedIndex=ddlRight.selectedIndex+1;
}
}
else
{
alert("请先选择要上移的项");
}
}
else
{
alert("该列表中没有数据");
}
}
相关文章推荐
- 左右两个Select列表框交换数据的JS代码,上下左右都可以移动数据,还可以置顶、沉底
- IOS开发笔记-01按钮操作-13.上下左右移动 14.代码优化
- 左右两个Select列表框交换数据的JS代码,上下左右都可以移动数据,还可以置顶、沉底,相信大家见到过,但觉得挺实用,与大家分享。
- 常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
- 【js】左右上下移动
- js实现键盘操作实现div的移动或改变的原理及代码
- 常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全(推荐)
- javascript实现listbox左右移动实现代码
- Js上下左右无缝隙滚动代码
- Js实现图片缩放上下左右移动效果
- 常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
- vs2005空间之ListBox有用的代码-- //向上下移动
- js实现键盘的上下左右控制图片移动
- js实现键盘操作实现div的移动或改变的原理及代码
- 常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
- 【AS3代码】键盘控制影片剪辑上下左右移动!!
- 常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
- js 操作Listbox js 获取Listbox选择的值的代码
- 常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
- 使用javascript操作多选列表框,实现动态增加删除,左右移动,上下排序移动等功能。