急~~~求大家解答
如何从一个select选中多个option,用javascript动态增加到右侧的select中?
[解决办法]
<script type="text/javascript">
function AddOptions()
{
var selectLable = document.getElementById("select1");
var select2 = document.getElementById("select2");
var options = selectLable.getElementsByTagName("option");
for (var i = 0; i < optio[code=HTML][/code]ns.length; i++)
{
if (options[i].selected)
{
select2.appendChild(options[i]);
}
}
}
</script>
<select id="select1" onchange="AddOptions()">
<option>aaa</option>
<option>bbb</option>
<option>ccc</option>
<option>ddd</option>
<option>eee</option>
</select>
<select id="select2">
</select>
[解决办法]
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
//获取当先选中的下拉框的 TEXT 和 VALUE 以及索引的值
string value = ddl.SelectedItem.Value;
string text = ddl.SelectedItem.Text;
int index = ddl.SelectedIndex;
//移除当前选中的值
ddl.Items.RemoveAt(index);
//在右边的下拉框中添加此项
ddl2.Items.Insert(0,new ListItem(text,value));
}
[解决办法]