我想显示选定下拉列表的相反值。
如果我从击球下拉菜单中选择“ A队”,那么保龄球队应该是“ B队”,反之亦然。< / p>
Batting:
<select class="battingTeam">
<option>-- Select Team --</option>
<option>Team A</option>
<option>Team B</option>
</select>
<div id="bowlingTeam"></div>
$(document).ready(function(){
$(".battingTeam").change(function(){
$("#bowlingTeam").html( 'Bowling:' + this.options[this.selectedIndex].textContent);
});
});
答案 0 :(得分:0)
$(document).ready(function(){
$(".battingTeam").change(function(){
var batTeam = $(this).val();
var bowlTeam = ( batTeam == "Team B" )?"Team A":"Team B";
$('#bowlingTeam').html("Bowling:" +bowlTeam );
});
});
答案 1 :(得分:0)
试
$(document).ready(function () {
$(".battingTeam").change(function () {
var value = (this.selectedIndex == 0) ? 0 : (this.selectedIndex == 1) ? 2 : 1;
(value == 0) ? $("#bowlingTeam").hide() : $("#bowlingTeam").show().html('Bowling:' + this.options[value].textContent);
});
});
<强> DEMO 强>
答案 2 :(得分:0)
为teams
选项添加一个类,然后您不需要知道具体值
<option class="team">Team A</option>
<option class="team">Team B</option>
JS
$(".battingTeam").change(function () {
$("#bowlingTeam").html('Bowling:' + $(this).find('.team:not(:selected)').text());
});
的 DEMO 强>