这是我的jsp代码:
<table class="table table-striped">
<thead>
<tr>
<th>
Column name
</th>
</tr>
</thead>
<tbody>
<c:forEach var="question" items="${questions}">
<tr>
<td>
<h4>${question.sequence} - ${question.questionText}</h4>
<c:forEach var="answer" items="${question.answers}">
<div class='answer'>
<input type='radio' name="question${question.id}" id='${answer.id}'/>
<label for='${answer.id}'> ${answer.answerText}</label>
</div>
</c:forEach>
</td>
<tr>
</c:forEach>
</tbody>
</table>
打印页面时,此代码在每次迭代后创建一个空的tr标记,并且html上的结果为:
<tbody>
<tr>
<td>
<h4>1 - Question 1?</h4>
<div class="answer">
<input type="radio" name="question1" id="1">
<label for="1">Answer 1.</label>
</div>
<div class="answer">
<input type="radio" name="question1" id="2">
<label for="2">Answer 2.</label>
</div>
</td>
</tr>
<tr>
</tr>
...... (some more iterations with the same result - a question and a empty tr tag)
</tbody>
任何人都知道我的代码发生了什么?
答案 0 :(得分:1)
你没有关闭循环中的tr。你错过了结束tr中的/。第二个<tr>
导致输出新行。