实现从一个ListBox向另一个ListBox中移动选中项,并按照value进行排序
2008-09-03 09:59
260 查看
实现从一个ListBox向另一个ListBox中移动选中项,并按照value进行排序
只是双击进行移动。
适合于IE和Firefox,其它没试过,呵呵。
<script language="javascript" type="text/javascript">
function MoveOne(listSrc, listDest) {
var option = document.createElement('option');
var nIndex = listSrc.selectedIndex;
var value = listSrc.options[nIndex].value;
var nLen;
if (nIndex == -1)
return;
option.appendChild(document.createTextNode(listSrc.options[nIndex].text));
option.setAttribute("value", value);
nLen = listDest.length;
for (var i = 0; i < nLen; i++) {
if (parseInt(listDest.options[i].value) > parseInt(value))
break;
}
if (i == nLen)
listDest.appendChild(option);
else
listDest.insertBefore(option, listDest.options[i]);
listSrc.remove(nIndex);
}
function B_AddOne_onclick() {
MoveOne(document.getElementById("<%=LB_Src.ClientID%>"), document.getElementById("<%=LB_Dest.ClientID%>"));
}
function B_RemoveOne_onclick() {
MoveOne(document.getElementById("<%=LB_Dest.ClientID%>"), document.getElementById("<%=LB_Src.ClientID%>"));
}
</script>
aspx中ListBox设置:
<asp:ListBox ID="LB_Src" runat="server" Height="300px" Width="200px" onDblClick="B_AddOne_onclick()">
<asp:ListItem Value="1">List1</asp:ListItem>
<asp:ListItem Value="2">List2</asp:ListItem>
<asp:ListItem Value="3">List3</asp:ListItem>
<asp:ListItem Value="4">List4</asp:ListItem>
<asp:ListItem Value="5">555555555</asp:ListItem>
<asp:ListItem Value="6">666666666666</asp:ListItem>
<asp:ListItem Value="7">777777777777</asp:ListItem>
<asp:ListItem Value="8">888888888888888</asp:ListItem>
<asp:ListItem Value="9">99999999999</asp:ListItem>
</asp:ListBox>
只是双击进行移动。
适合于IE和Firefox,其它没试过,呵呵。
<script language="javascript" type="text/javascript">
function MoveOne(listSrc, listDest) {
var option = document.createElement('option');
var nIndex = listSrc.selectedIndex;
var value = listSrc.options[nIndex].value;
var nLen;
if (nIndex == -1)
return;
option.appendChild(document.createTextNode(listSrc.options[nIndex].text));
option.setAttribute("value", value);
nLen = listDest.length;
for (var i = 0; i < nLen; i++) {
if (parseInt(listDest.options[i].value) > parseInt(value))
break;
}
if (i == nLen)
listDest.appendChild(option);
else
listDest.insertBefore(option, listDest.options[i]);
listSrc.remove(nIndex);
}
function B_AddOne_onclick() {
MoveOne(document.getElementById("<%=LB_Src.ClientID%>"), document.getElementById("<%=LB_Dest.ClientID%>"));
}
function B_RemoveOne_onclick() {
MoveOne(document.getElementById("<%=LB_Dest.ClientID%>"), document.getElementById("<%=LB_Src.ClientID%>"));
}
</script>
aspx中ListBox设置:
<asp:ListBox ID="LB_Src" runat="server" Height="300px" Width="200px" onDblClick="B_AddOne_onclick()">
<asp:ListItem Value="1">List1</asp:ListItem>
<asp:ListItem Value="2">List2</asp:ListItem>
<asp:ListItem Value="3">List3</asp:ListItem>
<asp:ListItem Value="4">List4</asp:ListItem>
<asp:ListItem Value="5">555555555</asp:ListItem>
<asp:ListItem Value="6">666666666666</asp:ListItem>
<asp:ListItem Value="7">777777777777</asp:ListItem>
<asp:ListItem Value="8">888888888888888</asp:ListItem>
<asp:ListItem Value="9">99999999999</asp:ListItem>
</asp:ListBox>
相关文章推荐
- Python实现字典按照value进行排序的方法分析
- C++中实现对map按照value值进行排序 - 菜鸟变身记 - 51CTO技术博客
- C++中实现对map按照value值进行排序
- C++中实现对map按照value值进行排序
- 转:C++中实现对map按照value值进行排序
- C++中实现对map按照value值进行排序 - 菜鸟变身记 - 51CTO技术博客
- 如何实现在客户端,使CheckBox按照选择的顺序进行排序--来自博问的问题
- Java中Map根据键值(key)或者值(value)进行排序实现
- MapReduce 按照Value值进行排序输出
- TreeMap按照value进行排序
- 基于BootStrap的Metronic框架实现页面链接收藏夹功能按钮移动收藏记录(使用Sortable进行拖动排序)
- C++中如何按照map中的value来进行排序
- properties文件的存取与Map键值对排序【按照value进行排序】
- Map按照Value值进行排序
- jquery控制listbox中项的移动并排序的实现代码
- MapReduce-WordCount实现按照value降序排序、字符小写、识别不同标点
- java8实现spark wordcount并且按照value排序输出
- Java中Map根据键值(key)或者值(value)进行排序实现
- Java Map 按照Value排序的实现方法
- PHP读取数据库并按照中文名称进行排序实现代码