简体   繁体   English

选择后如何禁用下拉菜单项?

[英]How can i disable an drop down menu item after selection?

Category is the first item yo will see i want it to be removed or disabled after is is selected so that it doesn't show when viewing the other drop down menu items. 类别是您选择后将要删除或禁用的第一个项目,因此在查看其他下拉菜单项目时不会显示。

<select NAME="category" style="width:130px; background-color:#FFF; font-weight:bold; font-size:12px;" ONCHANGE="setup(document.search1.category.value)"> 
  <option value="category" selected="selected">Category</option> 
  <option value="cleaning">Cleaning</option> 
  <option value="cooling">Cooling</option>
  <option value="heating">Heating</option> 
  <option value="kitchen">Kicthen</option> 
  <option value="lighting">Lighting</option> 
  <option value="washroom">Washroom</option> 
</select>

This will remove the slected Item 这将删除选中的项目

<select NAME="category" style="width:130px; background-color:#FFF; font-weight:bold; font-size:12px;" onchange="this.remove(this.selectedIndex);"> 
  <option value="category" selected="selected">Category</option> 
  <option value="cleaning">Cleaning</option> 
  <option value="cooling">Cooling</option>
  <option value="heating">Heating</option> 
  <option value="kitchen">Kicthen</option> 
  <option value="lighting">Lighting</option> 
  <option value="washroom">Washroom</option> 
</select>​

You should use it like this disabled = 'disabled' 您应该像这样使用它disabled = 'disabled'

<select NAME="category" style="width:130px; background-color:#FFF; font-weight:bold; font-size:12px;" onchange="javascript:this.disabled = 'disabled';"> 
  <option value="category" selected="selected">Category</option> 
  <option value="cleaning">Cleaning</option> 
  <option value="cooling">Cooling</option>
  <option value="heating">Heating</option> 
  <option value="kitchen">Kicthen</option> 
  <option value="lighting">Lighting</option> 
  <option value="washroom">Washroom</option> 
</select>​

If you want to remove the "category" line item after a user selects a different item from your drop down, you would do this: 如果要在用户从下拉菜单中选择其他项目后删除“类别”行项目,则可以执行以下操作:

<script type="text/javascript">
    $(document).ready(function () {

    $('#selectList').change(function () {
        if (this[0].value == "category")
        {
            this.remove(this[0]);
        }
    });

});
</script>

<select id='selectList' name="category" 
style="width:130px; background-color:#FFF; font-weight:bold; font-size:12px;"> 
    <option value="category">Category</option> 
    <option value="cleaning">Cleaning</option> 
    <option value="cooling">Cooling</option>
    <option value="heating">Heating</option> 
    <option value="kitchen">Kicthen</option> 
    <option value="lighting">Lighting</option> 
    <option value="washroom">Washroom</option> 
</select>

That will remove the Category row from the drop down and ONLY the category row. 这将从下拉列表中删除“类别”行,而仅删除“类别”行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在手机中选择#后,我需要下拉菜单关闭 - I need drop down menu to close after # selection in mobile 我如何在反应中进行验证,如果我从下拉菜单中选择了一个选项,那么该选项将在另一个下拉菜单中被禁用 - How can I put validation in react, that if I have choose an option from a drop down, then that option will be disable in the other drop down menu 如何根据下拉菜单选择隐藏/显示文本框? - How can I hide/show textboxes based on drop down menu selection? 如何基于下拉菜单选择用数据库中的数据预填充表单? - How Can I Prefill My form with data from my database based on drop down menu selection? 如何根据下拉菜单选择从下拉菜单中选择后显示复选框列表? - How to make a checkbox list appear after a selection from a drop-down menu, depending on drop-down menu selection? 用户单击项目后如何隐藏下拉菜单? - How to hide a drop down menu after user clicks on an item? 在下拉菜单中选择项目后如何运行onlick命令? - How to run the onlick command after I choose the item in drop down menu? 如何从柏树的下拉菜单中选择项目? - How can select item from drop-down menu in cypress? 从剃刀中的下拉菜单选择启用/禁用单选按钮 - enable/disable radio buttons from drop down menu selection in razor 如果没有元素,如何禁用下拉菜单 - How to disable the drop down menu if no element is there in it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM