sha*_*rad 6 javascript c# asp.net listbox
我有两个列表框(列表框1和列表框2).i使用以下javscript代码将值从一个列表框移动到另一个列表框.
<script language="javascript" type="text/javascript">
function fnMoveItems(lstbxFrom,lstbxTo)
{
var varFromBox = document.all(lstbxFrom);
var varToBox = document.all(lstbxTo);
if ((varFromBox != null) && (varToBox != null))
{
if(varFromBox.length < 1)
{
alert('There are no items in the source ListBox');
return false;
}
if(varFromBox.options.selectedIndex == -1) // when no Item is selected the index will be -1
{
alert('Please select an Item to move');
return false;
}
while ( varFromBox.options.selectedIndex >= 0 )
{
var newOption = new Option(); // Create a new instance of ListItem
newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text;
newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value;
varToBox.options[varToBox.length] = newOption; //Append the item in Target Listbox
varFromBox.remove(varFromBox.options.selectedIndex); //Remove the item from Source Listbox
}
}
return false;
}
</script>
Run Code Online (Sandbox Code Playgroud)
此代码将值从一个列表框移动到另一个列表框,但实际上当我尝试读取第二个列表框值时,其中一个值被复制,我无法读取这些值.当我检查它显示ListBox2.Items.Count为0
| 归档时间: |
|
| 查看次数: |
5222 次 |
| 最近记录: |