我有以下 HTML
<form>
<div class="answer1wrap">
<select id="mySelect">
<option value="void">Choose your answer</option>
<option value="To measure time">To measure time</option>
<option value="To measure distance">To measure distance</option>
<option value="To measure volume">To measure volume</option>
</select>
</div>
</form>
<button class="btn btn-default" id="checkbtn" onclick="answers();" type="button"><span class="glyphicon glyphicon-check"></span> Check answers</button>
我也有 javascript
function answers()
{
var selectedanswer=document.getElementById("mySelect").selectedIndex;
if (document.getElementsByTagName("option")[selectedanswer].value=="To measure time");{
alert("Thats correct");
}
}
我希望当按下按钮时,它会检查是否选择了“测量时间”选项并仅在选择时提醒我。但是,无论选择了哪个选项,它总是显示警报。
有任何想法吗?