<table class="table-editor">
<tbody>
<tr class="normal-row">
<td><input type="text" size="2" maxlength="2" placeholder="a1,1"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a1,2"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a1,3"></td>
</tr>
<tr class="normal-row">
<td><input type="text" size="2" maxlength="2" placeholder="a2,1"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a2,2"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a2,3"></td>
</tr>
<tr class="normal-row">
<td><input type="text" size="2" maxlength="2" placeholder="a3,1"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a3,2"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a3,3"></td>
</tr>
<tr class="normal-row">
<td><input type="text" size="2" maxlength="2" placeholder="a4,1"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a4,2"></td>
<td><input type="text" size="2" maxlength="2" placeholder="a4,3"></td>
</tr>
</tbody>
</table>
<input id="addcol" type="button" value="Add Column" />
<input id="remcol" type="button" value="Reomve Column" />
<input id="addrow" type="button" value="Add row" />
<input id="remrow" type="button" value="Remove row" />
$('#addcol').click(function() {
var $tablerow = $('table.table-editor').find('tr');
count = 0;
$tablerow.each(function(index, value){
count += 1;
var $listitem = $(this);
n = parseInt($listitem.index());
var $input = $('<input>', {
type: 'text',
maxlength: '2',
placeholder: 'a'
});
var $newRow = $("<td>");
$("table.table-editor tr:eq(" + n + ")").append($newRow.append($input));
$("input:text").attr("size", "2");
});
});
$('#remcol').click(function() {
var $tablerow = $('table.table-editor').find('tr');
$tablerow.each(function(index, value){
$("table.table-editor tr:eq("+index+") td:eq(-1)").remove();
});
});
$('#addrow').click(function() {
var $input = $('<input>', {
type: 'text',
maxlength: '2',
placeholder: 'a'
});
var $newRow = $("<td/>");
$('table.table-editor').append("<tr></tr>");
$('table.table-editor tr:eq(0) td').each(function(index, value){
$("table.table-editor tr:eq(-1)").append($input.append($input));
$("input:text").attr("size", "2");
});
});
$('#remrow').click(function() {
$('table.table-editor tr:eq(-1)').remove();
});
1. Некорректно работает добавление строк. Как это исправить?
2. Хочу, чтоб при добавлении новых ячеек в placeholder писалось а(номер столбца),(номер строки)