我正在學習只使用jQuery和PHP編寫測驗應用程序,沒有數據庫。我不能使用jquery爲標籤標籤設置html嗎?
我使用PHP來準備HTML文件的結構。然後使用jquery填充數據。
問題顯示正常。但選項的標籤標籤保持不定。
腳本:
var questions = [
{
\t
\t "statement": "The function <img src='images/1.png'>, where [x] denotes the greatest integer function, is defined for all x ϵ",
\t "ans1": "R",
\t "ans2": "R - {(-1, 1) U n: n ϵ I }",
\t "ans3": "R<sup>+</sup> - (0, 1)",
\t "ans4": "R - (n: n ϵ N)",
}
];
$(document).ready(function() {
\t var i = 0;
\t var j = 1;
\t while (i < questions.length) {
\t \t $("#question" + j).html('Q' + j + ". " + questions[i]["statement"]);
\t \t // the labels //
\t \t $("#question" + j + "-choice1").html(questions[i]["ans1"]);
\t \t //console.log($("#question" + j + "-choice1").html());
\t \t console.log(questions[i]["ans1"]);
\t \t $("#question" + j + "-choice2").html(questions[i]["ans2"]);
\t \t $("#question" + j + "-choice3").html(questions[i]["ans3"]);
\t \t $("#question" + j + "-choice4").html(questions[i]["ans4"]);
\t \t
\t \t i++;
\t \t j++;
\t }
});
下面是我使用創建標記的PHP腳本。
<?php
$numQues = 30; // max number of questions.
$i = 1;
while ($i <= $numQues) {
// careful with this string generator :)
echo '<div class="questions">
<p id="question' . $i . '"'. '></p>'.
'<input type="radio" name="ans' . $i .''. '><label id="question' . $i . '-choice1' .'"></label><br>'.
'<input type="radio" name="ans'. $i . '><label id="question' . $i . '-choice2' . '"></label><br>'.
'<input type="radio" name="ans'. $i . '><label id="question'. $i .'-choice3'.'"'.'></label><br>'.
'<input type="radio" name="ans' . $i . '><label id="question'. $i .'-choice4'.'"'.'></label><br>'.
'<button class="btn btn-primary pull-right" id="question-review'. $i . '"'. '>Mark for Review</button>
</div>';
$i++;
}
?>
您在'name'屬性末尾缺少雙引號字符。 – Barmar