用javascript写下拉列表,要用无序列表。谢谢

发布网友

我来回答

2个回答

热心网友

我写了右移选中项和右移所有项的2个相应方法,和左移一个道理,方法如下:
(注意,把你第二个select的id改为select2!!!)
<script type="text/javascript">
function rightMove()
{
var select1 = document.getElementById("select1");

// 获取当前选中项的索引
var index = select1.selectedIndex;
// 获取当前选中项的文本
var name = select1.options[index].text;

// 删除select1的选中项
if(index >= 0){
select1.options.remove(index);
}

// 向select2中添加该项
var select2 = document.getElementById("select2");
select2.options.add(new Option(name,index));

}
function rightMoveAll()
{
var select1 = document.getElementById("select1");
var select2 = document.getElementById("select2");
var length = select1.options.length;

for(var i=0;i<length;i++)
{
// 获取当前项的索引
var index = select1.options[0].value;
// 获取当前项的文本
var name = select1.options[0].text;
// 删除指定项
select1.options.remove(0);

// 向select2中添加项
select2.options.add(new Option(name,i));
}
}
</script>

热心网友

你说呢...

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com