gpt4 book ai didi

javascript - 级联下拉删除上一个选择

转载 作者:行者123 更新时间:2023-11-30 13:20:07 24 4
gpt4 key购买 nike

我想在 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>

最佳答案

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

关于javascript - 级联下拉删除上一个选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10518078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com