我已收到用戶必須選擇大學校園的作業,然後單擊繼續按鈕。我不能工作的唯一的事情是,當沒有選中單選按鈕並單擊繼續按鈕時,應該顯示一條錯誤消息,指出'您尚未選擇大學校園,請重試。'單擊需要的按鈕時出現錯誤消息
我有一切工作,但這個錯誤代碼。我似乎無法得到它。出現錯誤消息,顯示「未定義」,該按鈕來自按鈕的點擊功能。有人可以幫忙嗎?
<html>
<head>
<style>
input, label { line-height: 1.5em; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form>
<div>
<input type="radio" name="university" value="Ah, we are not on the same site" id="Belfast">
<label for="Belfast">Belfast</label>
</div>
<div>
<input type="radio" name="university" value="Yeah, we are on the same campus" id="Jordanstown">
<label for="Jordanstown">Jordanstown</label>
</div>
<div>
<input type="radio" name="university" value="Ah, we are not on the same site" id="Coleraine">
<label for="Coleraine">Coleraine</label>
</div>
<div>
<input type="radio" name="university" value="Ah, we are not on the same site" id="Magee">
<label for="Magee">Magee</label>
</div>
<div id="log"></div>
</form>
<input type="button" value="Continue" id="click">
</body>
</html>
<script>
$(function() {
$("#click").click(function() {
alert($("input[type=radio]:checked").val());
})
});
</script>
如果沒有選擇單選按鈕,則沒有元素的值應該返回。這應該解釋警報。至於阻止提交,請查看作爲回調參數的'event'對象。 – 2013-03-07 15:41:58