아래 테이블 행을 인라인으로 편집 할 수있는 코드가 있습니다. 그러나 해당 행의 모든 TD를 편집합니다. 내 문제는 코드와 함께 아래에 설명되어 있습니다. 어떤 도움을 주셔서 감사합니다.특정 TD 요소를 무시하십시오.
<tbody>
<tr>
<th scope="row">Test</th>
<td class="amount">$124</td>
<td class="amount" id="" >$154</td>
<td class="diff">- 754</td>
</tr>
</tbody>
위 표는 참고 용일뿐입니다. 내가 이루고자 노력한 것은 단순히 특정 행 내의 TD를 편집하는 것인데, 이지만, diff
TD을 무시하면됩니다.
저는 jQuery를 처음 접했고 jQuery 책을 통해 다음 코드를 얻었습니다.
$(document).ready(function() {
TABLE.formwork('#current-expenses');
});
var TABLE = {};
TABLE.formwork = function(table){
var $tables = $(table);
$tables.each(function() {
var _table = $(this);
_table.find('thead tr').append($('<th class="edit"> </th>'));
_table.find('tbody tr').append($('<td class="edit"><input type="button" value="Edit"/></td>'))
});
$tables.find('.edit :button').live('click', function(e) {
TABLE.editable(this);
e.preventDefault();
});
}
TABLE.editable = function(button) {
var $button = $(button);
var $row = $button.parents('tbody tr');
var $cells = $row.children('td').not('.edit');
if($row.data('flag')) { // in edit mode, move back to table
// cell methods
$cells.each(function() {
var _cell = $(this);
_cell.html(_cell.find('input').val());
})
$row.data('flag',false);
$button.val('Edit');
}
else { // in table mode, move to edit mode
// cell methods
$cells.each(function() {
var _cell = $(this);
_cell.data('text', _cell.html()).html('');
if($('td.diff')){
var $input = $('<input type="text" />')
.val(_cell.data('text'))
.width(_cell.width() - 16);
_cell.append($input);
}
})
$row.data('flag', true);
$button.val('Save');
}
}
나는 그것이 diff
클래스 TD를 무시 할 수 있도록 코드를 변경하려고 시도했지만, 지금까지 운이 없었 없습니다.
var $cells = $row.children('td').not('.edit').not('.diff');
와
를 교체 숨기기 같이 ... 당신이 무시 무엇을 의미합니까 : 후 – Val
나는 무시하는 것을 무시했습니다. 나는 단지 그 특정한 클래스를 무시하고 싶었다. '편집 '버튼을 클릭하면됩니다. –