两个列表框中的元素相互移动(源代码)
2006-08-20 21:56
225 查看
演示地址:http://datuo.roii.net/java/demo/selectToselect.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>移动</title>
<style type="text/css">
form{background:#CCCCCC;
width:500px;
}
td{width:150px;
height:150px;
text-align:center;
}
select{ width:100px;
height:180px;
}
td div{width:100px;
height:150px;
text-align:center;
}
input{width:100px;
height:30px;
margin:5px;
}
</style>
</head>
<body>
<form id="myForm" name="myForm" method="post" action="#">
<table>
<tr>
<td>
<select name="listLeft" id="listLeft" size="10" multiple="multiple" ondblclick="removeOne(listLeftnode,listRightnode);" >
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
<option value="f">f</option>
<option value="g">g</option>
</select> </td>
<td>
<div>
<input type="button" name="allRightMove" id="allRightMove" value=" >> " onclick="removeAll(listLeftnode,listRightnode);"/><br />
<input type="button" name="rightMove" id="rightMove" value=" > " onclick="removeOne(listLeftnode,listRightnode);"/><br />
<input type="button" name="leftMove" id="leftMove" value=" < " disabled="disabled" onclick="removeOne(listRightnode,listLeftnode);" /><br />
<input type="button" name="allLeftMove" id="allLeftMove" value=" << " disabled="disabled" onclick="removeAll(listRightnode,listLeftnode);" />
</div>
</td>
<td><select name="listRight" size="10" multiple="multiple" id="listRight" ondblclick="removeOne(listRightnode,listLeftnode);">
</select>
</td>
</tr>
</table>
<script type="text/javascript">
var listLeftnode = document.getElementById("listLeft");
var listRightnode = document.getElementById("listRight");
var btallRightMove = document.getElementById("allRightMove");
var btRightMove = document.getElementById("rightMove");
var btLeftMove = document.getElementById("leftMove");
var btallLeftMove = document.getElementById("allLeftMove");
function isEmpty()
{
if(listLeftnode.options.length<1)
{
btallRightMove.setAttribute("disabled","disabled");
btRightMove.setAttribute("disabled","disabled");
}
else
{
btallRightMove.removeAttribute("disabled");
btRightMove.removeAttribute("disabled");
}
if(listRightnode.options.length<1)
{
btallLeftMove.setAttribute("disabled","disabled");
btLeftMove.setAttribute("disabled","disabled");
}
else
{
btallLeftMove.removeAttribute("disabled");
btLeftMove.removeAttribute("disabled");
}
}
function removeOne(beginList, endList)
{
var flag=false;
for(i=beginList.options.length-1; i>=0; i--)
{
if(beginList.options[i].selected)
{ flag=true;
var tempOption = beginList.options[i];
beginList.remove(i);
endList.add(tempOption, endList.last);
}
}
if(!flag)
{
alert("您没有选择,不能移动!!");
}
isEmpty();
}
function removeAll(beginList,endList)
{
for(i=beginList.options.length-1; i>=0; i--)
{
var tempOption = beginList.options[i];
beginList.remove(i);
endList.add(tempOption, endList.first);
}
isEmpty();
}
</script>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>移动</title>
<style type="text/css">
form{background:#CCCCCC;
width:500px;
}
td{width:150px;
height:150px;
text-align:center;
}
select{ width:100px;
height:180px;
}
td div{width:100px;
height:150px;
text-align:center;
}
input{width:100px;
height:30px;
margin:5px;
}
</style>
</head>
<body>
<form id="myForm" name="myForm" method="post" action="#">
<table>
<tr>
<td>
<select name="listLeft" id="listLeft" size="10" multiple="multiple" ondblclick="removeOne(listLeftnode,listRightnode);" >
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
<option value="f">f</option>
<option value="g">g</option>
</select> </td>
<td>
<div>
<input type="button" name="allRightMove" id="allRightMove" value=" >> " onclick="removeAll(listLeftnode,listRightnode);"/><br />
<input type="button" name="rightMove" id="rightMove" value=" > " onclick="removeOne(listLeftnode,listRightnode);"/><br />
<input type="button" name="leftMove" id="leftMove" value=" < " disabled="disabled" onclick="removeOne(listRightnode,listLeftnode);" /><br />
<input type="button" name="allLeftMove" id="allLeftMove" value=" << " disabled="disabled" onclick="removeAll(listRightnode,listLeftnode);" />
</div>
</td>
<td><select name="listRight" size="10" multiple="multiple" id="listRight" ondblclick="removeOne(listRightnode,listLeftnode);">
</select>
</td>
</tr>
</table>
<script type="text/javascript">
var listLeftnode = document.getElementById("listLeft");
var listRightnode = document.getElementById("listRight");
var btallRightMove = document.getElementById("allRightMove");
var btRightMove = document.getElementById("rightMove");
var btLeftMove = document.getElementById("leftMove");
var btallLeftMove = document.getElementById("allLeftMove");
function isEmpty()
{
if(listLeftnode.options.length<1)
{
btallRightMove.setAttribute("disabled","disabled");
btRightMove.setAttribute("disabled","disabled");
}
else
{
btallRightMove.removeAttribute("disabled");
btRightMove.removeAttribute("disabled");
}
if(listRightnode.options.length<1)
{
btallLeftMove.setAttribute("disabled","disabled");
btLeftMove.setAttribute("disabled","disabled");
}
else
{
btallLeftMove.removeAttribute("disabled");
btLeftMove.removeAttribute("disabled");
}
}
function removeOne(beginList, endList)
{
var flag=false;
for(i=beginList.options.length-1; i>=0; i--)
{
if(beginList.options[i].selected)
{ flag=true;
var tempOption = beginList.options[i];
beginList.remove(i);
endList.add(tempOption, endList.last);
}
}
if(!flag)
{
alert("您没有选择,不能移动!!");
}
isEmpty();
}
function removeAll(beginList,endList)
{
for(i=beginList.options.length-1; i>=0; i--)
{
var tempOption = beginList.options[i];
beginList.remove(i);
endList.add(tempOption, endList.first);
}
isEmpty();
}
</script>
</form>
</body>
</html>
相关文章推荐
- 列表之间内容相互移动,列表添加元素
- jQuery两个列表中元素相互交换Demo
- html 两个多选下拉列表元素互相移动
- 两个select列表相互移动
- 用js实现两个select下拉框之间的元素互相移动
- 在两个元素间实现"无缝"移动
- 用js实现两个select下拉框之间的元素互相移动
- C# listbox的上下移动,拖动排序,两个listbox相互拖动
- Python两个列表里元素对应相乘,实现方法
- jquery的Flexigrid改造,支持选中行内容获取,两个表格行相互移动,行选中事件,支持dwr
- jquery实现选项在两个下拉列表之间选择性移动的功能
- 两个select多选模式的选项相互移动(示例代码)
- 两个table之间相互移动数据
- 初学移动开发技术_两个页面相互跳转,并且向上一个活动传递数据并显示
- JavaScript Select和Option列表元素上下左右移动
- 实现列表框元素的左右移动
- 【python】两个list列表逐元素相减
- 两个table之间相互移动数据
- 编写一个交错合并列表元素的函数。例如:给定的两个列表为[a,B,C]和[1,2,3],函数返回[a,1,B,2,C,3]。
- 实现在两个JList中元素移动and实现数据更改后排序