菜鸟求助,在线等

NiuniuASP 2006-07-19 11:13:42
有三个下拉列表框,s1,s2,s3,加载时s1有列表值,s2,s3为空,要求实现选择s1中的某选项,通过一个按钮控制(也可以双击该选项)把这个值同时添加到s2,s3中,并且在s1中删除该选项.
然后选择s2中的某选项,通过一个另按钮控制(也可以双击该选项),把这个值添加到s1中,并且删除s2和s3中的该选项.

请大家帮忙并给出代码,本人对javascript不熟,谢谢.
...全文
171 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
NiuniuASP 2006-07-20
  • 打赏
  • 举报
回复
可以给出详细代码吗?谢谢
kusaboy 2006-07-20
  • 打赏
  • 举报
回复
设置id值 使用innerHTML方法可以实现
moodkingdom 2006-07-20
  • 打赏
  • 举报
回复
使用DOM
NiuniuASP 2006-07-20
  • 打赏
  • 举报
回复
UP
wideroad 2006-07-20
  • 打赏
  • 举报
回复
<!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>
<title>无标题页</title>
<script type="text/javascript" src="../shared/Common.js"></script>
</head>
<body>
<select id="Select1">
</select>
<input type="button" value=">>>" onclick="add()" />
<input type="button" value="<<<" onclick="remove()" />
<select id="Select2">
</select>
<select id="Select3">
</select>

</body>
</html>
<script type="text/javascript">
var select1 = $("Select1");
var select2 = $("Select2");
var select3 = $("Select3");

var optionArray = new Array(new Array("item1","item1"),new Array("item2","item2"),new Array("item3","item3"),new Array("item4","item4"),new Array("item5","item5"));

function addOption(select,optionText,optionValue)
{
var option = document.createElement("option");
select.options.add(option);
option.innerText = optionText;
option.value = optionValue;
}

function removeOption(select,index)
{
select.options.remove(index);
}

function add()
{
var i = select1.selectedIndex;
if(i != -1)
{
addOption(select2,select1.options[i].text,select1.options[i].value);
addOption(select3,select1.options[i].text,select1.options[i].value);
removeOption(select1,i);
}
refreshAll();
}

function remove()
{
var i = select2.selectedIndex;
if(i != -1)
{
addOption(select1,select2.options[i].text,select2.options[i].value);
removeOption(select2,i);
removeOption(select3,i);
}
refreshAll();
}

function setDefault(select)
{
if(select.options.length > 0)
{
select.selectedIndex = 0;
}
}

function refreshAll()
{
setDefault(select1);
setDefault(select2);
setDefault(select3);
}

function init(select,optionArray)
{
for(var i=0;i<optionArray.length;i++)
{
addOption(select,optionArray[i][0],optionArray[i][1]);
}
refreshAll();
}
init(select1,optionArray);
</script>
NiuniuASP 2006-07-20
  • 打赏
  • 举报
回复
是我没表述清楚吗?怎么大家不肯帮忙呢?

87,909

社区成员

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

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