我在HTML上创建了三个下拉菜单,并且制作了一个JavaScript程序来提醒您有重复的选定值。如果在警报后选定的下拉列表在警报后返回其默认值,该怎么办。
function hey() {
var count = document.getElementsByClassName('data').length;
//var cars = document.getElementsByClassName('data')[0].value;
var arr = [];
var text = "";
var i = 0;
while (i < count) {
if ((document.getElementsByClassName('data')[i].value) == "") {} else {
arr.push(document.getElementsByClassName('data')[i].value);
}
i++;
}
document.getElementById("demo").innerHTML = arr;
var uniqueval = arr.filter(function(itm, i, arr) {
return i == arr.indexOf(itm);
});
if (arr.length > uniqueval.length) {
alert("Has duplicate")
}
}
<div class="info">
<select name="type" class="data" onchange="hey()">
<option value="">---select---</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
<option value="students">Students</option>
</select>
<select name="class" class="data" onchange="hey()">
<option value="">---select---</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
<option value="students">Students</option>
</select>
<select name="class" class="data" onchange="hey()">
<option value="">---select---</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
<option value="students">Students</option>
</select>
<p id="demo"></p>
</div>
<p>When I select another dropdown and its been already selected <br>
Theres have an alert message and when I click OK I want to return its default value which is --select--</p>
我要在选定下拉菜单的警报后返回--select--值。