<html>
<head>
<script type="text/javascript">
function selectBoxRemove(sourceID) {
//get the listbox object from id.
var src = document.getElementById(sourceID);
//iterate through each option of the listbox
for(var count= src.options.length-1; count >= 0; count--) {
//if the option is selected, delete the option
if(src.options[count].selected == true){
try {
src.remove(count, null);
} catch(error) {
src.remove(count);
}
}
}
}
function listboxSelectDeselect(listID, isSelect) {
var listbox = document.getElementById(listID);
for(var count=0; count < listbox.options.length; count++) {
listbox.options[count].selected = isSelect;
}
}
function listboxMove(listID, direction) {
var listbox = document.getElementById(listID);
var selIndex = listbox.selectedIndex;
if(-1 == selIndex) {
alert("Please select an option to move.");
return;
}
var increment = -1;
if(direction == 'up')
increment = -1;
else
increment = 1;
if((selIndex + increment) < 0 ||
(selIndex + increment) > (listbox.options.length-1)) {
return;
}
var selValue = listbox.options[selIndex].value;
var selText = listbox.options[selIndex].text;
listbox.options[selIndex].value = listbox.options[selIndex + increment].value
listbox.options[selIndex].text = listbox.options[selIndex + increment].text
listbox.options[selIndex + increment].value = selValue;
listbox.options[selIndex + increment].text = selText;
listbox.selectedIndex = selIndex + increment;
}
</script>
</head>
<body>
Click on below button. Now change some values in form and click the button again. <br>
<select id="lsbox" name="lsbox" size="10" multiple="multiple">
<option value="1">India</option>
<option value="2">United States</option>
<option value="3">China</option>
<option value="4">Italy</option>
<option value="5">Germany</option>
<option value="6">Canada</option>
<option value="7">France</option>
<option value="8">United Kingdom</option>
</select> <br>
<button onclick="selectBoxRemove('lsbox');">Delete Selected Options</button>
<button onclick="listboxSelectDeselect('lsbox', true);">Select All</button>
<button onclick="listboxSelectDeselect('lsbox', false);">Deselect All</button>
<button onclick="listboxMove('lsbox', 'up');">Move Up</button>
<button onclick="listboxMove('lsbox', 'down');">Move Down</button>
</body>
</html>
分享到:
相关推荐
实现上移下移功能,具体绑定一个数据源,操作数据源,最后把数据源赋值给数据源。
主要介绍了JavaScript列表框listbox全选和反选的实现方法,涉及javascript操作列表框listbox的技巧,非常具有实用价值,需要的朋友可以参考下
ListBox动态添加数据删除数据和上移下移, 无刷新。
复选框实现datagridview全选反选和全不选,datagridview换颜色(选中复选框之后)
mfc listbox选中弹出菜单,选中listbox里面的一个值,然后点击右键,会弹出一个菜单,非常简单的 例子
c# ListBox 删除选定的多项 本人在网上找了好久,没找到。自己写了一个,参考了好几本书,和一些网络资源,几经修改,终于成功!虽然简单,但对我学c#菜鸟还是挺难得!还附带了一个错误的代码!本人未找到错误,但是...
js,listbox,select,item,selectedValue,selectedIndex
使用javascript实现ListBox左右全选,单选,多选,全请。需要的朋友可以过来参考下,希望对大家有所帮助
用ListBox.Items.Remove()方法删除一个item后,其items集合和SelectedItems集合都会改变,不好用一般的循环来一次性删除多个选择项。 本人也是初学者,小小心得和初学者共享,高手莫笑,并请指教。
文件功能描述: 对ListBox进行了拓展,实现了两个方面的功能 1:增加了每项的高度,原版默认每行的高度太小,外观不好看 2:增加了对项的双击事件
主要介绍了ListBox实现上移,下移,左移,右移的简单实例。需要的朋友可以过来参考下,希望对大家有所帮助
双击移除LISTBOX选项[服务器控件],无刷新,用JS来实现。
TlistBox选中全部
本案例介绍了如何在ListBox中实现选择项功能,需要的请看
C#js实现ListBox左边的移动到右边,右边的移动到左边
主要介绍了asp.net listbox单选全选取消的应用,需要的朋友可以参考下
js 实现对 asp.net服务器空件listbox的元素进行排序 同步更新数据库排序列的值。
本文实例讲述了JavaScript控制listbox列表框的项目上下移动的方法。分享给大家供大家参考。具体分析如下: 这段JS代码可以控制listbox内的元素向上或者向下移动,这个功能非常有用。下面是详细的代码 代码如下:...
ListBox 项的双击事件 ListBox 项的双击事件