0

类别是您将看到的第一个项目,我希望在选择它后将其删除或禁用,以便在查看其他下拉菜单项时不会显示。

<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>
4

3 回答 3

1

这将删除选定的项目

<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>​
于 2012-11-07T16:14:09.700 回答
0

你应该像这样使用它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>​
于 2012-11-07T16:18:48.470 回答
0

如果您想在用户从您的下拉列表中选择不同的项目后删除“类别”行项目,您可以这样做:

<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>

这将从下拉列表中删除类别行,并且仅删除类别行。

于 2012-11-07T16:19:58.383 回答