我打印出存儲在數據庫中的問題列表的形式。用戶應該選擇最多10個複選框,但似乎我的JavaScript被忽略。我是否爲了實現這個目標而採取了一些基本措施?我正在用LAMP在虛擬機中創建它。我試過在Eclipse和瀏覽器中運行代碼,但沒有任何反應。這裏是我的代碼:不能限制(試過多個片段)選擇複選框的數量
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Question Selection</title>
<script type="text/javascript">
function chkcontrol(j) {
var total = 0;
for (var i = 0; i < document.questions.questions.length; i++) {
if (docment.questions.questions[i].checked) {
total = total + 1;
}
if (total > 10) {
alert("Please select only 10 questions");
document.questions.questions[i].checked = false;
return false;
}
}
}
</script>
</head>
<body>
<?php echo "<br />"; ?>
<form id="questions" name="questions" action="GenerateQuiz" method="post">
<table border="2" style="margin:0 auto; padding:5px">
<thead>
<tr>
<th>Questions</th>
<th>Include in Quiz</th>
</tr>
</thead>
<tbody>
<?php
$count = 1;
// Print a row for each record in the returned query
foreach($questionList as $key => $row) {
echo "
<tr>
<td style='text-align:left;'>$row[questionText]</td>
<td style='text-align:center;'><input type='checkbox' name='questions[]' onclick='chkcontrol($count)' value='$row[questionText]' /></td>
</tr>";
$count++;
}
?>
</tbody>
</table>
<div align="center">
<br />
<input type="submit" value="Take Quiz" />
</div>
</form>
</body>
</html>
我在我的代碼實現,「文件」是拼寫錯誤。我糾正了這一點,但它並沒有使代碼正常工作。 – slickset
檢查你一個拼寫錯誤在這裏如果'(docment.questions.questions [I] .checked){...'你缺少一個「O」文件 –
抓到,我覺得就像你正在鍵入您的評論。雖然沒有運氣。 – slickset