以下代码每次只能运行一次
var selectedVal = $('#drpGender_0').find("option:selected").text();
if (selectedVal == "Male") {
$('#drpGender_1').find("option:contains('Male')").text('Male').attr("selected", false);
$('#drpGender_1').find("option:contains('Female')").text('Female').attr("selected", "selected");
}
else if (selectedVal == "Female") {
$('#drpGender_1').find("option:contains('Female')").text('Female').attr("selected", false);
$('#drpGender_1').find("option:contains('Male')").text('Male').attr("selected", "selected");
}
};
提前致谢
答案 0 :(得分:1)
$('#drpGender_0').on('change', function() {
var selectedVal = $('#drpGender_0').val();
if (selectedVal == "Male") {
$('#drpGender_1').val('Female');
} else if (selectedVal == "Female") {
$('#drpGender_1').val('Male');
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="drpGender_0">
<option value="">Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<select id="drpGender_1">
<option value="">Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
&#13;
你也可以使用代码
$('#drpGender_0').on('change', function() {
var selectedVal = $('#drpGender_0').val();
if (selectedVal == "Male") {
$('#drpGender_1').find("option:contains('Female')").attr("selected", "selected");
} else if (selectedVal == "Female") {
$('#drpGender_1').find("option:contains('Male')").attr("selected", "selected");
}
});
答案 1 :(得分:0)
试试这段代码:
$('#drpGender_0').on('change', function() {
if (this.value == "Male") {
$('#drpGender_1').find("option:contains('Male')").text('Male').attr("select ed", false);
$('#drpGender_1').find("option:contains('Female')").text('Female').attr("selected", "selected");
}
else if (this.value == "Female") {
$('#drpGender_1').find("option:contains('Female')").text('Female').attr("selected", false);
$('#drpGender_1').find("option:contains('Male')").text('Male').attr("selected", "selected");
}
});