散分!散分!谁能帮我调通下面的JS?

vanco 2002-06-17 11:59:32
最近写了个JavaScript实现将一个列表框中的内容动态传递到另一列表框,可出现一莫名其妙的错误,恳请JS高手帮我调一下,不胜感激!!!
...全文
30 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiushuiwuhen 2002-06-17
  • 打赏
  • 举报
回复
修正代码为:(错误原因有三条)
function transform(from_list,to_list){
for(var i=0;i<from_list.options.length;i++){
if(from_list.options[i].selected){
var str=from_list.options[i].text
to_list.options[to_list.options.length++]=new Option(str,str)
from_list.remove(i--)
}
}
}
vanco 2002-06-17
  • 打赏
  • 举报
回复
完整的文档如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- created by WangCong 2002.06.13 html\public\choose.htm -->
<HTML><HEAD><TITLE>选择</TITLE>
<META content="text/html; charset=GB2312" http-equiv=Content-Type><LINK
href="../../css/style.css" rel=stylesheet type=text/css>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 text=#000000 topMargin=0 marginheight="30%"
marginwidth="30%">

<Script language="JavaScript">
//从from_list中的选项转移到to_list
function transform(from_list,to_list){
var from_length=from_list.options.length
var to_length=to_list.options.length
for(var i=0;i<from_length;i++){
if(from_list.options[i].selected){
var str=from_list.options[i].text
to_list.options[to_length++]=new Option(str,str)
from_list.options[i--]=null
}
}
}

//将LIST框中的选项向上移动
function up_click(cur_list){
var cur_index=cur_list.selectedIndex
var str=cur_list.options[cur_index].text
cur_list.options[cur_index].text=cur_list.options[cur_index-1].text
cur_list.options[cur_index].value=cur_list.options[cur_index-1].text
cur_list.options[cur_index-1].text=str
cur_list.options[cur_index-1].value=str
cur_list.selectedIndex=cur_index-1
}

//将LIST框中的选项向下移动
function down_click(cur_list){
var cur_index=cur_list.selectedIndex
var str=cur_list.options[cur_index].text
cur_list.options[cur_index].text=cur_list.options[cur_index+1].text
cur_list.options[cur_index].value=cur_list.options[cur_index+1].text
cur_list.options[cur_index+1].text=str
cur_list.options[cur_index+1].value=str
cur_list.selectedIndex=cur_index+1
}
</Script>

<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%" align="center">
<TBODY>
<TR>
<TD width="100%" align="center"> <BR>
<FORM action=/save.jsp id=form1 method=post name=form1>
<TABLE align=center border=0 width="363">
<TBODY>
<TR>
<TD bgColor=#000066 height="149" >
<TABLE align=center border=0 cellPadding=5 cellSpacing=1
width="100%" height="100%">
<TR bgColor=#ffffff>
<TD width="28%" height="144" align="center" valign="top">
<select name="total" multiple size="10">
<option value="技术部">技术部</option>
<option value="开发部">开发部</option>
<option value="人事部">人事部</option>
</select>
</TD>
<TD height="144" width="20%" align="center">
<p>
<input type="button" value="add" onClick="transform(total,needed)">
</p>
<p>
<input type="button" value="delete" onClick="transform(needed,total)">
</p>
</TD>
<TD align="center" height="144" width="30%" valign="top">
<select name="needed" multiple size="10">
<option value="销售部">销售部</option>
</select>
</TD>
<TD colspan="2" height="144" width="22%" align="center">
<p>
<input type="button" name="up" value="up" onClick="up_click(needed)">
</p>
<p>
<input type="button" name="down" value="down" onClick="down_click(needed)">
</p>
</TD>
</TR>
<TBODY> </TBODY>
</TABLE>
</TD>
</TR></TBODY></TABLE>


<br><div align="center">
<input type="submit" name="Submit2" value="确定" onClick="javascript:window.opener.location.href='6.htm'; window.close()">
        
<input type="button" name="Submit24" value="取消" onClick="javascript:window.close();">
</div>

</FORM></TD></TR></TBODY></TABLE>
<!--- end buttom --->
</BODY></HTML>
vanco 2002-06-17
  • 打赏
  • 举报
回复
感谢孟大哥!
我已给分不过我写的JS却不知问题出在哪,孟大哥可否帮我看一下?
<Script language="JavaScript">
//从from_list中的选项转移到to_list
function transform(from_list,to_list){
var from_length=from_list.options.length
var to_length=to_list.options.length
for(var i=0;i<from_length;i++){
if(from_list.options[i].selected){
var str=from_list.options[i].text
to_list.options[to_length++]=new Option(str,str)
from_list.options[i--]=null
}
}
}

</Script>
孟子E章 2002-06-17
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/723/723099.xml?temp=.8441736
孟子E章 2002-06-17
  • 打赏
  • 举报
回复
http://go6.163.com/colorweb/js/radioforselect.html
孟子E章 2002-06-17
  • 打赏
  • 举报
回复
<html>
<head>
<script language="JavaScript">

<!--


function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {

var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}
if (found != true) {
destList.options[len] = new Option(srcList.options[i].text);
len++;
}
}
}
}

function deleteFromDestList() {
var destList = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
}
}
}
// -->
</SCRIPT>
</head>
<body>
<center>
<form method="POST">
<table bgcolor="#FFFFCC">

<tr>
<td bgcolor="#FFFFCC" width="85">
<select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td bgcolor="#FFFFCC" width="74" align="center">
<input type="button" value=" 增加到右边 " onClick="javascript:addSrcToDestList()">
<br><br>
<input type="button" value=" 从右边删除 " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="69">
<select size="6" name="destList" multiple>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧