這似乎工作75%的時間和模態函數執行的參數可用,但表中的每一個按鈕,我會得到一個未捕獲的SyntaxError:意外的標識符。這是否與不正確的關閉有關?我的谷歌搜索作爲一個潛在的問題落在了那裏,但我無法在這裏實施任何解決方案到我目前的方法。Javascript中的意外標識符for循環
html += '<thead><th>Question</th><th>Answer 1</th><th>Answer 2</th><th>Answer 3</th><th>Answer 4</th></thead>';
for (var i = 0; i < questions.length; i++) {
question = questions[i].question;
questionTitle = question.q;
answer1title = question.a1;
answer2title = question.a2;
html += '<tr><td class="question"><b>'
+ question.q
+ '</b></td><td class="answer1">'
+ question.a1
+ '</td><td class="answer2">'
+ question.a2
+ '</td><td class="answer3">'
+ question.a3
+ '</td><td class="answer4">'
+ question.a4
+ '</td><td class="edit">'
+ '<button onclick="openQuestionModal(\''+questionTitle+'\', \''+answer1title+'\', \''+answer2title+'\')" class="btn btn-small btn-primary" id="questionEdit" type="button">Edit</button>'
+ '</td></tr>';
}
$('#questionsTable').append(html);
你從哪裏獲得「問題」,它看起來如何? –
「questionTitle」,「answer1title」或「answer2title」中是否有任何單引號或雙引號? – Ian
我認爲一些或多個標籤沒有關閉,因此語法錯誤。 –