当用户点击列表框中的项目时,我试图取消选择项目(一旦选中)。 我有一个脚本,用于取消用户点击的项目,但即使第一次选择该项目,也会发生这种情况。 这就是我所拥有的: JS:
function deselect()
{
var list = document.getElementById('<%=ddlCity.ClientID%>');
var listLength = list.options.length;
for (var i = 0; i < listLength; i++) {
if (list.options[i].selected) {
list.selectedIndex = -1;
}
}
}
和html:
<asp:ListBox ID="ddlCity" CssClass="formfield" runat="server" DataSourceID="SqlDataSourceCity"
DataTextField="Description" DataValueField="CityID" SelectionMode="Multiple" onclick="deselect();"
OnDataBound="DropDownList3_DataBound"></asp:ListBox>
任何想法如何编辑JS以在选择值后取消选择值,但是当用户第一次选择值时要选择该值。 谢谢,Laziale