gpt4 book ai didi

jQuery 将动态创建的列表放入
    标签内

转载 作者:行者123 更新时间:2023-12-01 03:53:05 24 4
gpt4 key购买 nike

.append()似乎并没有达到目的,它同时放置了 <ul> & </ul>在顶部。我该怎么做?

(fullQuestion 只是一个 <li>,它是为每个问题生成的)

function writeQuestions() {

$('#container').append("<ul>\n");

len = questions.qestion.length;
for (var i = 0; i < len; i++) {

var answerRdy = [];
var qestionRdy = questions.qestion[i];
answerRdy[0] = questions.answer[i][0];
answerRdy[1] = questions.answer[i][1];
answerRdy[2] = questions.answer[i][2];
answerRdy[3] = questions.answer[i][3];
var divID = "question-" + i;
var formID = "form-" + i;
var CurrentForm = i;

var writeAnswer = [];
writeAnswer[writeAnswer.length] = ("\n<br />`<li id='{0}'>`\n<form id='{1}' name='{2}'>\n").format(divID, formID, CurrentForm);
writeAnswer[writeAnswer.length] = ("<b>" + qestionRdy + "</b><br />\n");
for (var n=0; n<=3; n++) {
writeAnswer[writeAnswer.length] = ("<input type='radio' name='answerN' value='{0}' /> {1} <br />\n").format(n, answerRdy[n]);
}
writeAnswer[writeAnswer.length] = ("<input type='submit' value='Submit your answer'>\n</form>\n</li><!--{0}-->").format(divID);


var joinQuestion = writeAnswer.join();
// var joinQuestion = "<ul>\n" + joinQuestion + "\n</ul>"
exp = /,/gi;
var fullQuestion = joinQuestion.replace(exp, "");

$('#container').append(fullQuestion);
}

for (var i=0; i < len; i++) {
var formID = document.forms["form-" + i];
$(formID).bind("submit", validate);
}

$('#container').append("\n</ul>");

}

最佳答案

您没有正确使用 append 。

先创建一个 UL

var $ul = $('<ul>');
$('#container').append($ul);
//all other code
$ul.append(fullQuestion);

并删除此行 $('#container').append("\n</ul>");

关于jQuery 将动态创建的列表放入 <ul> 标签内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6056522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com