显示一个选择选项基于其他选择选项
<select name = "team1">
<option>Computer Science</option>
<option>Mathematics</option>
<option>Bioinformatic</option>
<option>Management Sciences</option>
</select>
<select name = "team2">
<option>Computer Science</option>
<option>Mathematics</option>
<option>Bioinformatic</option>
<option>Management Sciences</option>
</select>
我如何可以使用上面的代码,根据“TEAM2”什么价值“TEAM1” have.If我在队1的选择选项,选择计算机科学,后来我不希望计算机科学出现在“team2”的选项中。显示一个选择选项基于其他选择选项
你可以给一个ID来选择,并检查特定元素的选择。因此,您可以区分team1和team2,并删除一些具有相同值的team2-selection。它可能是这样的:
<body>
<select onChange="jsFunction()" id="team1" >
<option onclick="jsFunction()">Computer Science</option>
<option>Mathematics</option>
<option>Bioinformatic</option>
<option>Management Sciences</option>
</select>
<select id="team2">
<option>Computer Science</option>
<option>Mathematics</option>
<option>Bioinformatic</option>
<option>Management Sciences</option>
</select>
<script>
function jsFunction(){
var team1 = document.getElementById("team1");
var team2 = document.getElementById("team2");
for (i=0;i<4;i++){
team2.remove(0);
}
var position=0;
for (i=0;i<4;i++){
if (i!=team1.selectedIndex){
team2.options[position] = new Option(team1.options[i].value);
position=position+1;
}
}
}
</script>
</body>
你可以在这里找到解决方案:http://*.com/questions/3301688/how-do - 您 - 获取最当前选择的选项-IN-A-选择 - 通过JavaScript的,在这里http://*.com/questions/1085801/get-selected-value-of-dropdownlist-using-javascript – Bine 2015-02-09 14:21:21
我将使用什么命令来加载Java脚本? – 2015-02-09 14:31:43
我写它像
个 – 2015-02-09 14:32:24
您可以使用复选框为这些options.Its解决您的问题。
但我想在选择选项中使用它, – 2015-02-09 14:23:33
为什么PHP?
HTML:
<select name = "team1">
</select>
<select name = "team2">
</select>
JS:
var l = [
'Computer Science',
'Mathematics',
'Bioinformatic',
'Management Sciences'
];
$('select').change(function() {
var me = $(this);
var other = me.siblings();
var text = me.children(':selected').text();
other.each(function() {
var select = $(this);
var currentText = select.children(':selected').text();
select.empty();
$.each(l, function(k, d) {
if(d != text) {
select.append($('<option></option>').html(d).attr('selected', d == currentText));
}
});
});
});
$('select').change().change();
将选择后的JS身体标记? – 2015-02-09 15:08:59
是在
如何包含jquery? – 2015-02-09 15:13:39
欢迎堆栈溢出!这个问题在信息上有点短暂。你可以分享你的尝试,并且遇到了什么问题? 请参阅[如何问*上的问题(http://*.com/help/how-to-ask) – 2015-02-09 14:15:29