jquery实现添加删除一行

var rowCount = 0;
function addLine() {
rowCount++;
var tbLine = "<tr id=\"option"+ rowCount+"\"><td>选项名:<input type=\"text\" name=\"optionText\" /></td>" +
"<td>选项值:<input type=\"text\" name=\"optionValue\" /></td>" +
"<td><a href=\"#\" onclick=\"removeLine("+rowCount+")\">删除</a></</td></tr>";
$("#optionLine").append(tbLine);
}

function removeLine(rowIndex) {
$("#option" + rowIndex).remove();
rowCount--;
}

使用c:forEach实现

<c:forEach items="${optionList }" var="optionList" varStatus="line">
<tr id="option${line.index }">
<td>选项名:<input type="text" name="optionText"
value="${optionList.optionText }"></td>
<td>选项值:<input type="text" name="optionValue"
value="${optionList.optionValue }"></td>
<td><a href="#" onclick="removeLine(${line.index})">删除</a></</td>
</tr>
</tr>
</c:forEach>

猜你喜欢

转载自yun-200.iteye.com/blog/2297223