1

我想在 html 中有 7 个下拉框。它们都将填充相同的数据。我想要做的是,当第一个下拉列表被选中时,它会从下一个下拉列表中删除选定的项目。所以,如果你有数字:A,B,C,D,E,F,G,H,I 在一个下拉列表中如果我在第一个下拉列表中选择 B 然后在下一个下拉列表中它应该只显示 A,C,D ,E,F,G,H,I 等最多 7 个下拉菜单。我不知道在 JavaScript 或 JQuery 中解决这个问题的最佳方法是什么。提前感谢您的帮助。

<table>
    Selected Options: <div id="123"></div>
      <tr>
         <td class="assessmentHeader" align="left"><U> Diagnosis: -  </U><br/> <!---Added code 88898 Created 7 dropdowns for Diagnosis  05/04/2012--->
           <!---<font style="visibility:hidden"><textarea name="diagnosis" rows="2" cols="5" disabled="disabled">NULL</textarea></font><br/>--->                                                                              
           Primary  : <select name="Primary" onchange="selected(this)">
           <option value=""></option>
           <cfloop query="DCheck">
           <option value="#DCheck.cDescription#" >#DCheck.cDescription#</option></cfloop>                                                      
           </select> &nbsp;&nbsp; <br/> <br/>
           Secondary: <select name="Secondary" onchange="selected(this)">
           <option value=""></option>
           <cfloop query="DCheck">
           <option value="#DCheck.cDescription#">#DCheck.cDescription#</option> </cfloop>
                                                                                </select>&nbsp;&nbsp;<br><br />
           Third &nbsp;   : <select name="Third" onchange="selected(this)">
           <option value=""></option>
           <cfloop query="DCheck">
           <option value="#DCheck.cDescription#">#DCheck.cDescription#</option></cfloop>
                                                                                </select>&nbsp;&nbsp;<br><br/>
            Fourth   : <select name="Fourth" onchange="selected(this)">
            <option value=""></option>
            <cfloop query="DCheck">
            <option value="#DCheck.cDescription#">#DCheck.cDescription#</option></cfloop>
                                                                                </select>&nbsp;&nbsp;<br><br/>
            Fifth  &nbsp; : <select name="Fifth" onchange="selected(this)">
            <option value=""></option>
            <cfloop query="DCheck">
            <option value="#DCheck.cDescription#">#DCheck.cDescription#</option></cfloop>
                                                                                </select>&nbsp;&nbsp;<br><br/>
            Sixth &nbsp; : <select name="Sixth" onchange="selected(this)">
            <option value=""></option>
            <cfloop query="DCheck">
            <option value="#DCheck.cDescription#">#DCheck.cDescription#</option></cfloop>
                                                                                </select>&nbsp;&nbsp;<br><br/>
            Seventh  : <select name="Seventh" onchange="selected(this)">
            <option value=""></option>
            <cfloop query="DCheck">
            <option value="#DCheck.cDescription#">#DCheck.cDescription#</option></cfloop>
                                                                                </select>&nbsp;&nbsp;<br><br />
          </td>                    
         </tr>
      </table>
4

1 回答 1

3

http://jsfiddle.net/iambriansreed/AyxSE/

这适用于无限select标签。

jQuery

$('#select-group select').change(function(){

    var values = [];
    $('#select-group select').each(function(){
        if(this.value.length > 0)
            values.push(this.value);
    });

   $('#select-group select optgroup').each(function(){
        $(this).after('<option>'+          $(this).attr('label')+'</option>').remove();
    });

    $('#select-group select option').each(function(){   
        if($.inArray(this.value, values) > -1 &&
           !this.selected)                
        $(this).after('<optgroup label="'+this.value+'"></optgroup>').remove();
    });

});​

HTML

<div id="select-group">
    <select>
        <option value="">Select a ...</option>
        <option>A</option>
        <option>B</option>
        <option>C</option>
        <option>D</option>
        <option>E</option>
        <option>F</option>
        <option>G</option>
    </select>
    <select>
        <option value="">Select a ...</option>
        <option>A</option>
        <option>B</option>
        <option>C</option>
        <option>D</option>
        <option>E</option>
        <option>F</option>
        <option>G</option>
    </select>

</div>​
于 2012-05-09T14:42:08.677 回答