我有一个带有禁用初始值“请选择值”的下拉列表,当我单击它时,它再次显示为选项之一。有没有办法删除它,这样我就只会看到我的项目,而不会从选择的选项中看到“请选择值”?
<asp:DropDownList ID="ddlRole" runat="server" AppendDataBoundItems="true" Width="115">
<asp:ListItem Selected="True" Text="Please select value" Value="" disabled />
</asp:DropDownList>
最佳答案
<asp:DropDownList ID="ddlRole" runat="server" AppendDataBoundItems="true" Width="115" onclick="removeFirst()">
<asp:ListItem Selected="True" Text="Please select value" Value="plsselect" />
<asp:ListItem>First Item</asp:ListItem>
<asp:ListItem>Second Item</asp:ListItem>
</asp:DropDownList>
在 Javascript 中
<script>
function removeFirst() {
var select = document.getElementById('<%= ddlRole.ClientID %>');
for (i = 0; i < select.length; i++) {
if (select.options[i].value == 'plsselect') {
select.remove(i);
}
}
}
</script>
关于c# - DropDownList 单击时从选择中删除 "Please select value"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22679952/