웹 응용 프로그램에서 jQuery를 사용하여 HTML 테이블에서 행을 동적으로 추가/삭제하고있었습니다.jQuery를 사용하여 행을 삭제하는 동안 개별 td 제거
개인의 TD 요소 (전체 행이 아닌)를 삭제해야한다는 요구 사항이있었습니다.
$(function() {
/* adding new row to existing table */
// HTML template of a row
$("#contactInfo").each(function() {
$("button.addCommentRow", this).live('click', function() {
var curr_row = $(this).closest('tr');
var html = '<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> ' + col_ninth + '</td> <td><button type="button" class="addCommentRow">+</button> <button type="button" class="deleteCommentRow">-</button> </td> </tr>';
var newRow = $(html).insertAfter(curr_row); // add after the last
newRow.find('.addCommentRow, .deleteCommentRow').button();
newRow.find('.deleteCommentRow').button().click(function() {
newRow.find("td:nth-child(9)").remove();
newRow.find("td:nth-child(10)").remove();
});
});
});
});
을 그래서, 9 내 행에서 10 번째 TD 요소를 제거하고 싶었 삭제에 다음과 같이
내 jQuery 코드입니다.
위 코드 (삭제 부분 만)가 작동하지 않는 것 같습니다.
아이디어를 얻으려면 제안을 받아야합니다.
고마워,
피셔.
테이블 행이 올바르게 렌더링되기 위해서는 일치 또는 열 구분 된 셀이 필요하므로 레이아웃을 혼란스럽게 만들 것입니다. 대신 이러한 셀의 내용을 삭제할 수 있습니까? – Paddy
게시물을 보내주세요. –
@Paddy : 셀 내용도 삭제할 수 있습니다. 어떻게하면됩니까? – Pritish