□ | 성명 | 나이 | 성별 |
| 홍길동 | 23 | 여 |
| 파파룰라 | 25 | 남 |
□ | 뽀로로 | 12 | 남 |
◐ Script_Row추가
function fn_addRow(addData, chkCnt) {
if (Number(chkCnt) > 0) {
var tblObj = $("#testTbl > tbody:last");
for(var k=0; k<Number(chkCnt); k++) {
var orw = $("<tr></tr>");
var rChk = $("<td><input type='checkbox' name='chkObject' value='"+addData[k].dbKey+"'></td>");
var rName = $("<td></td>").text(addData[k].name);
var rAge = $("<td></td>").text(addData[k].age );
var rGender = $("<td></td>").text(addData[k].gender);
tblObj.append(row);
row.append(rChk);
row.append(rName);
row.append(rAge);
row.append(rGender);
}
}
}
◐ Script_체크된 데이터 Row 삭제
function fn_delRow(chkObjNm) {
if ($("input[name="+chkObjNm+"]").is(":checked")){
if (confirm("삭제 하시겠습니까?")) {
for(var i=$("[name='"+chkObjNm+"']:checked").length-1; i>-1; i--){
$("[name='"+chkObjNm+"']:checked").eq(i).closest("tr").remove();
}
}
} else {
alert("선택된 데이터가 없습니다.");
}
}
◐ HTML
<table summary="Test" cellpadding="0" cellspacing="0" id="testTbl">
<caption> Test </caption>
<colgroup>
<col width="10%"/>
<col width="30%"/>
<col width="30%"/>
<col width="30%"/>
</colgroup>
<thead>
<th scope="col"><input type="checkbox" onClick="fn_allChecked();" /></th>
<th scope="col">성명</th>
<th scope="col">나이</th>
<th scope="col">성별</th>
</thead>
<tbody>
<c:choose>
<c:when test="${!empty testList}">
<c:forEach begin="0" var="testList" items="${testList}" varStatus="index">
<tr>
<td></td>
<td>${testList.testName}</td>
<td>${testList.testAge}</td>
<td>${testList.testGender}</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr><td colspan="4">검색결과가 없습니다.</td></tr>
</c:otherwise>
</c:choose>
</tbody>
</table>
<div>
<a href="#" onClick="fn_btnChoice()">선택</a>
</div>
<div>
<a href="#" onClick="fn_delRow('chkObject');">삭제</a>
</div>