javascript實(shí)現(xiàn)listbox左右移動(dòng)實(shí)現(xiàn)代碼
更新時(shí)間:2010年05月26日 22:05:38 作者:
javascript實(shí)現(xiàn)listbox左右移動(dòng)實(shí)現(xiàn)代碼,需要的朋友可以參考下。
1。 html部分:
<table cellSpacing="0" borderColorDark="#ffffff" cellPadding="3" width="460"
align="left" borderColorLight="#000000" border="1">
<tr bgColor="#cccccc">
<td align="center" width="180"><b>所有地區(qū)</b> <asp:HiddenField ID="HidDistrictId" runat="server" /> </td>
<td align="center" width="60"> </td>
<td align="center" width="180"><b>已選地區(qū)</b></td>
</tr>
<tr >
<td bgcolor="#cccccc" style="height: 200px; width: 180px;" >
<asp:listbox id="listNewEmp" runat="server" Height="200px" Width="180px" SelectionMode="Single"></asp:listbox></td>
<td valign="top" align="center" bgcolor="#cccccc" style="height: 200px; width: 60px;">
<asp:Panel ID="Panel1" runat="server" Height="180px" >
<br> <br>
<%--<asp:Button style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體" Text="選擇→" ID="btnReceSendToRight" runat="server" OnClick="btnReceSendToRight_Click"/>--%>
<INPUT type="button" value="選擇→" onclick = "add('listNewEmp','listright','HidDistrictId')" Text="選擇→" style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體">
<br>
<br>
<INPUT type="button" value="←刪除" onclick = "move('listright')" style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體" Text="←刪除">
<%--<asp:Button style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體" Text="←刪除" ID="btnReceSendToLeft" runat="server" OnClick="btnReceSendToLeft_Click"/>--%>
</asp:Panel>
</td>
<td bgcolor="#cccccc" style="height: 200px;">
<asp:listbox id="listright" runat="server" Height="200px" Width="180px" SelectionMode="Multiple"></asp:listbox>
</td>
</tr>
</table>
2。 javascript 部分:
<script language="Javascript">
function add(sourlist, deslist,hidId)
{ //添加
var objres = document.getElementById(sourlist);
var objsel = document.getElementById(deslist);
var customOptions;
for(var i = objres.options.length - 1 ;i >= 0;i--)
{
if(objres.options[i].selected)
{
customOptions = document.createElement("OPTION");
customOptions.text = objres.options[i].text;
customOptions.value = objres.options[i].value;
if (objsel.options.length>0)
objsel.remove(objsel.options.length - 1);
document.getElementById(hidId).value = customOptions.value;
objsel.add(customOptions,0);
}
}
return false;
}
function move(deslist) { //刪除
var objres = document.getElementById(deslist);
objres.remove(objres.options.length - 1);
}
</script>
3.。cs部分
存儲(chǔ)是存 HidDistrictId.Value里的值,具體部分,用的時(shí)候再調(diào)節(jié)
4。 效果圖:
復(fù)制代碼 代碼如下:
<table cellSpacing="0" borderColorDark="#ffffff" cellPadding="3" width="460"
align="left" borderColorLight="#000000" border="1">
<tr bgColor="#cccccc">
<td align="center" width="180"><b>所有地區(qū)</b> <asp:HiddenField ID="HidDistrictId" runat="server" /> </td>
<td align="center" width="60"> </td>
<td align="center" width="180"><b>已選地區(qū)</b></td>
</tr>
<tr >
<td bgcolor="#cccccc" style="height: 200px; width: 180px;" >
<asp:listbox id="listNewEmp" runat="server" Height="200px" Width="180px" SelectionMode="Single"></asp:listbox></td>
<td valign="top" align="center" bgcolor="#cccccc" style="height: 200px; width: 60px;">
<asp:Panel ID="Panel1" runat="server" Height="180px" >
<br> <br>
<%--<asp:Button style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體" Text="選擇→" ID="btnReceSendToRight" runat="server" OnClick="btnReceSendToRight_Click"/>--%>
<INPUT type="button" value="選擇→" onclick = "add('listNewEmp','listright','HidDistrictId')" Text="選擇→" style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體">
<br>
<br>
<INPUT type="button" value="←刪除" onclick = "move('listright')" style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體" Text="←刪除">
<%--<asp:Button style="WIDTH: 48px; HEIGHT: 24px; font-family:宋體" Text="←刪除" ID="btnReceSendToLeft" runat="server" OnClick="btnReceSendToLeft_Click"/>--%>
</asp:Panel>
</td>
<td bgcolor="#cccccc" style="height: 200px;">
<asp:listbox id="listright" runat="server" Height="200px" Width="180px" SelectionMode="Multiple"></asp:listbox>
</td>
</tr>
</table>
2。 javascript 部分:
復(fù)制代碼 代碼如下:
<script language="Javascript">
function add(sourlist, deslist,hidId)
{ //添加
var objres = document.getElementById(sourlist);
var objsel = document.getElementById(deslist);
var customOptions;
for(var i = objres.options.length - 1 ;i >= 0;i--)
{
if(objres.options[i].selected)
{
customOptions = document.createElement("OPTION");
customOptions.text = objres.options[i].text;
customOptions.value = objres.options[i].value;
if (objsel.options.length>0)
objsel.remove(objsel.options.length - 1);
document.getElementById(hidId).value = customOptions.value;
objsel.add(customOptions,0);
}
}
return false;
}
function move(deslist) { //刪除
var objres = document.getElementById(deslist);
objres.remove(objres.options.length - 1);
}
</script>
3.。cs部分
存儲(chǔ)是存 HidDistrictId.Value里的值,具體部分,用的時(shí)候再調(diào)節(jié)
4。 效果圖:

您可能感興趣的文章:
- JS ListBox的簡單功能實(shí)現(xiàn)代碼
- js 獲取Listbox選擇的值的代碼
- 使用javascript實(shí)現(xiàn)ListBox左右全選,單選,多選,全請
- JavaScript如何從listbox里同時(shí)刪除多個(gè)項(xiàng)目
- 用JavaScript實(shí)現(xiàn)類似于ListBox功能示例代碼
- JavaScript控制兩個(gè)列表框listbox左右交換數(shù)據(jù)的方法
- 輕松使用jQuery雙向select控件Bootstrap Dual Listbox
- jquery控制listbox中項(xiàng)的移動(dòng)并排序
- 基于JQUERY的兩個(gè)ListBox子項(xiàng)互相調(diào)整的實(shí)現(xiàn)代碼
- jquery控制listbox中項(xiàng)的移動(dòng)并排序的實(shí)現(xiàn)代碼
- jquery移動(dòng)listbox的值原理及代碼
- JS與jQuery實(shí)現(xiàn)ListBox上移,下移,左移,右移操作功能示例
相關(guān)文章
DropDownList獲取的SelectIndex一直為0的問題
由于初始化判斷出錯(cuò)導(dǎo)致每次傳到服務(wù)器的時(shí)候會(huì)初始化一次,這就導(dǎo)致每次獲取DropDownList的SelectIndex的時(shí)候只能是02014-06-06.Net Core3.0 WEB API中使用FluentValidation驗(yàn)證(批量注入)
這篇文章主要介紹了.Net Core3.0 WEB API中使用FluentValidation驗(yàn)證(批量注入),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12ajaxpro.dll 控件實(shí)現(xiàn)異步刷新頁面
用ajaxpro.dll控件實(shí)現(xiàn)異步刷新頁面的代碼,需要的朋友可以參考下。2009-11-11asp.net 中國身份證號(hào)碼驗(yàn)證代碼 非正則
asp.net 中國身份證號(hào)碼驗(yàn)證,需要的朋友可以參考下。2009-11-11asp.net下使用jQuery.AutoComplete完成仿淘寶商品搜索自動(dòng)完成功能(改進(jìn)了鍵盤上下選擇體驗(yàn))
其實(shí)這個(gè)已經(jīng)是個(gè)比較常見的功能了,網(wǎng)上也有很多人做過這個(gè)了,但是很多都是僅僅做了一些基本的網(wǎng)頁上自動(dòng)完成功能,沒有與具體的數(shù)據(jù)庫進(jìn)行聯(lián)動(dòng),我今天所介紹這個(gè)自動(dòng)完成的就是我修改的jQuery.AutoComplete+數(shù)據(jù)庫的一個(gè)解決方案。2010-05-05