說$未定義,對象預計..實際上我想驗證是否所有單選按鈕檢查單擊按鈕時! help plz
<script type="text/javascript">
$(document).on('click', 'form', function() {
var validate = true;
var unanswered = new Array();
// Loop through available sets
$('.qselections').each(function() {
// Question text
var question = $(this).prev().text();
// Validate
if (!$(this).find('input').is(':checked')) {
// Didn't validate ... dispaly alert or do something
unanswered.push(question);
validate = false;
}
});
if (unanswered.length > 0) {
msg = "Please answer the following questions:\n" + unanswered.join('\n');
alert(msg);
}
return validate;
});
</script>
您是否包含對jQuery的引用?你有沒有在任何其他腳本之前包含該參考? – Yuck
我已經更新了代碼。在之後,我已將腳本放入了我的身體。 – Student