我想添加我的页面一些div和另一个标签。我想给出这样的独特类名:
dataType: "json",
success: function (msg) {
var c = eval(msg.d);
var html = ''; //'<tbody>';
for (var i = 0; i < c.length; i++) {
var className = "questionContainer " + i;
html += "<div class=" + className + ">";
html += "<div class=question><b>Question" + (i + 1) + ":</b>" + c[i].Name + "?</div>";
html += "<div class=answers><ul>";
for (var j = 0; j < c[i].Choses.length; j++) {
html += "<li> <label><input type=radio name=q1" + i + i + "id=q1-a />" + c[i].Choses[j].Name + "</label></li>";
}
html += "</ul></div>";
html += "<div class=btnContainer><div class=prev></div><div class=next><a class=btnNext>Next >></a></div> <div class=clear></div></div></div>";
}
html += '</div>';
// $('#dataTable').empty();
$('.as').append(html);
}
});
});
</script>
<head>
<body>
<h1>jQuiz Demo Page</h1>
<div class="as"></div>
</body>
</head>
但我的html节目
<div id="0" class="questionContainer" 0=""> like that how can I fixed?
空间必须在里面。
答案 0 :(得分:0)
你在课程名称后面有一个空格,你需要在下一行把它放在它周围......
var className = "questionContainer" + i;
html += "<div class='" + className + "'>";
答案 1 :(得分:0)
尝试:
var className = "questionContainer"+ i +"";