如果select下拉菜单的值为NULL,则应该停止加载页面。 jQuery的工作提醒用户的问题,但页面仍然延续到下一页。任何援助都会很棒。由于页仍然使用event.preventDefault()重新加载;
卢克
<fieldset class="form-group">
<label for="question-1">1. What age group are you?</label> <br>
<select class="drop-down" id = "ageChoice">
<option value="">Please Select</option>
<option value="16minus">16 or below</option>
<option value="16-18">16 to 18</option>
<option value="19-25">19 to 25</option>
<option value="26-34">26 to 34</option>
<option value="35-42">35 to 42</option>
<option value="43-50">43 to 50</option>
<option value="51-60">51 to 60</option>
<option value="61plus">61+</option>
</select>
</fieldset>
<input class="btn btn-primary" type="button" id= "next" value="Next" onClick="location.href='first-test.html' ">
$("#next").click(function() {
var age = $('#ageChoice');
if (age.val() === '') {
event.preventDefault();
alert("Please select your age group, thank you.");
}
else
return;
});
检查你的控制台,应该有一个关于'event'未定义的错误。它作为回调函数的参数。 –
嗨,感谢您的回复,抱歉,我是jQuery新手,你的意思如下: https://jsfiddle.net/uvyqtsxn/ 如果是这样,似乎没有工作。再次感谢您的回应。 – luke121