【发布时间】:2021-08-30 09:05:45
【问题描述】:
- 第一个选项是默认选项,因此会检索并比较其他选项中的选项文本。
- 现在,在显示警告消息后,我想清除在 2 号和 3 号中选择的选项,而不是默认的 1 号选项。
function check(){
var $fruits = [];
$("select.fruits").each(function() {
var $two = $(this).find("option:selected").text();
$fruits.push($two)
})
for ($i= 1; $i < $fruits.length; $i++) {
for ($j= 0; $j < 5; $j++) {
if ($fruits[$i] == "Apple" && $fruits[$i+$j] == "Banana") {
alert ("Since you have selected Apple, you cannot select Banana");
$("select.fruits").val(""); // this one clears all the options including the default**
return false;
}
if ($fruits[$i] == "Banana" && $fruits[$i+$j] == "Apple") {
alert ("Since you have selected Banana, you cannot select Apple");
$("select.fruits").val(""); // this one clears all the options including the default
return false;
}
}
}
}
【问题讨论】:
标签: javascript php jquery node.js reactjs