Cascading DropDown删除上一个选定的 [英] Cascading DropDown Remove Previous Selected

查看:92
本文介绍了Cascading DropDown删除上一个选定的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to have 7 dropdown boxes in html. They will all get populated the same data. What I am trying to do is when the first dropdown is selected it would remove the selected item from the next dropdown. So, if you Have Numbers: A,B,C,D,E,F,G,H,I in one dropdown if I select B in the first drop down then in the next dropdown it should only show A,C,D,E,F,G,H,I and so on up to 7 dropdowns. I dont know what would be the best way to approach this in JavaScript or JQuery. Thanks for your help in advance.

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


推荐答案

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

这适用于无限选择标签。

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

这篇关于Cascading DropDown删除上一个选定的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆