使用javascript删除lisbox asp.net中的选定项
我有一个javascript函数,当在asp.net中单击按钮时触发使用javascript删除lisbox asp.net中的选定项,javascript,asp.net,.net,Javascript,Asp.net,.net,我有一个javascript函数,当在asp.net中单击按钮时触发 function DeleteItem() { var dropDownListRef = document.getElementById("<%= lstboxFieldValues.ClientID %>"); var optionsList = ''; if ( dropDownListRef.value.length > 0 )
function DeleteItem()
{
var dropDownListRef = document.getElementById("<%= lstboxFieldValues.ClientID %>");
var optionsList = '';
if ( dropDownListRef.value.length > 0 )
{
var itemIndex = dropDownListRef.selectedIndex;
if ( itemIndex >= 0 )
dropDownListRef.remove(itemIndex);
}
else
{
alert('Please select an item');
dropDownListRef.focus();
dropDownListRef.select();
}
//for (var i=0; i<dropDownListRef.options.length; i++)
//{
//var optionText = dropDownListRef.options[i].text;
//var optionValue = dropDownListRef.options[i].value;
//if ( optionsList.length > 0 )
// optionsList += ';';
// optionsList += optionText;
// optionsList += ';';
// optionsList += optionValue;
//}
}
函数DeleteItem()
{
var dropdownlessref=document.getElementById(“”);
var optionsList='';
如果(dropdownlessref.value.length>0)
{
var itemIndex=DropDownstref.selectedIndex;
如果(itemIndex>=0)
删除(项目索引);
}
其他的
{
警报(“请选择一项”);
dropdownlestref.focus();
dropdownlestref.select();
}
//对于(变量i=0;i 0)
//选项列表+=';';
//选项列表+=选项文本;
//选项列表+=';';
//选项列表+=选项值;
//}
}
资料来源:
它正在删除列表框中的所有项目
它希望通过什么编辑仅删除所选项目 使用
RemoveAt
尝试此代码
itemindex
存储在int值中
dropDownListRef.Items.RemoveAt(itemIndex);