我有一个包含多个选择的下拉菜单。每个都有一个选项值。When three of these are selected, I'm supposed to have some text show up to the right of the box. 到目前为止,一切都很好。
我的问题是只选择这三个来显示文本,其余的什么都不显示。问题是我可以使用 来让其中两个工作!== 'value1' && 'value2'
,但我不知道只选择这三个的最佳方法。
这是我的代码:
HTML
<select id="award-type">
<option value="">choose one</option>
<option value="award1">Award 1</option>
<option value="award2">Award 2</option>
<option value="award3">Award 3</option>
<option value="award4">Award 4</option>
<option value="award5">Award 5</option>
<option value="award6">Award 6</option>
</select>
<div class="award-text"></div>
和JS:
function dropDownSelect() {
$('#award-type').on('change', function (e) {
var selectValue = $(this).val();
if (selectValue == 'award1') {
$('.award-text').show().text("you won award 1");
}
if (selectValue == 'award2') {
$('.award-text').show().text("you won award 2");
}
if (selectValue == 'award3') {
$('.award-text').show().text("you won award 3");
}
else if (selectValue !== 'award1' && 'award2' && 'award3') {
$('.award-text').show().text(" ");
}
});
}
任何想法将不胜感激!