标题:2个listbox问题 多选的时候不能实现想要的效果 郁闷
只看楼主
njitpippo
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2006-4-25
 问题点数:0 回复次数:1 
2个listbox问题 多选的时候不能实现想要的效果 郁闷

<html>
<head>
<title>Multi</title>
<script language="javascript">
function moveToList2(e){
if(e.selectedIndex!=-1){//判断是否有选择
for(var i=0;i<e.length;i++){
if(e.options[i].selected==true){
var len2=document.form1.list2.length-1;
var txt=e.options[i].text;
var value=e.options[i].value;
document.form1.list2.options[len2+1]=new Option(txt,value);

e.options[i]=null;
}
}
e.selectedIndex=-1;
}
}

function moveToList1(e){
if(e.selectedIndex!=-1){//判断是否有选择
for(var i=0;i<e.length;i++){
if(e.options[i].selected==true){
var len1=document.form1.list1.length-1;
var txt=e.options[i].text;
var value=e.options[i].value;
document.form1.list1.options[len1+1]=new Option(txt,value);

e.options[i]=null;
}
}
e.selectedIndex=-1;
}
}
</script>
</head>

<body>
<form action="" method="post" name="form1">
<table width="200" border="0" align="center">
<tr>
<td rowspan="5">
<select size="10" name="list1" multiple="multiple">
<option value="java">java</option>
<option value="jsp">jsp</option>
<option value="vb">vb</option>
<option value="delphi">delphi</option>
</select>
</td>
<td>&nbsp;</td>
<td rowspan="5">
<select size="10" name="list2" multiple="multiple">
<option value="asp">asp</option>
<option value="asp.net">asp.net</option>
<option value="php">php</option>
<option value="c++">c++</option>
</select>
</td>
</tr>
<tr>
<td align="center"><input type="button" value=" >> " onclick="moveToList2(document.form1.list1)"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="center"><input type="button" value=" << " onclick="moveToList1(document.form1.list2)"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>


上面是我写的代码,在选择多个的情况下会出错误,1下午都没有解决好

搜索更多相关主题的帖子: listbox 效果 
2007-05-10 19:08
njitpippo
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2006-4-25
得分:0 

人气不行啊,还是我自己搞掂了
<html>
<head>
<title>Multi</title>
<script language="javascript">
function moveToList2(e){
if(e.selectedIndex!=-1){//判断是否有选择
for(var i=0;i<e.length;i++){
if(e.options[i].selected==true){
var len2=document.form1.list2.length-1;
var txt=e.options[i].text;
var value=e.options[i].value;
document.form1.list2.options[len2+1]=new Option(value,txt);
//设置将要清空的option的value为""
e.options[i]=null;

//i--
i--;
}
}
e.selectedIndex=-1;
}
}

function moveToList1(e){
if(e.selectedIndex!=-1){//判断是否有选择
for(var i=0;i<e.length;i++){
if(e.options[i].selected==true){
var len1=document.form1.list1.length-1;
var txt=e.options[i].text;
var value=e.options[i].value;
document.form1.list1.options[len1+1]=new Option(value,txt);

e.options[i]=null;

i--;
}
}
e.selectedIndex=-1;
}
}
</script>
</head>

<body>
<form action="" method="post" name="form1">
<table width="200" border="0" align="center">
<tr>
<td rowspan="5">
<select size="10" name="list1" multiple="multiple">
<option value="java">java</option>
<option value="jsp">jsp</option>
<option value="vb">vb</option>
<option value="delphi">delphi</option>
</select>
</td>
<td>&nbsp;</td>
<td rowspan="5">
<select size="10" name="list2" multiple="multiple">
<option value="asp">asp</option>
<option value="asp.net">asp.net</option>
<option value="php">php</option>
<option value="c++">c++</option>
</select>
</td>
</tr>
<tr>
<td align="center"><input type="button" value=" >> " onClick="moveToList2(document.form1.list1)"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="center"><input type="button" value=" << " onClick="moveToList1(document.form1.list2)"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>


2007-05-10 22:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-138331-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020341 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved