5
I tried to create an empty table so that when the user clicks in the middle of the field <td>
appears a <input type="text" />
to type.
Follows the code:
$(function () {
$("td").click(function () {
var conteudoOriginal = $(this).text();
$(this).addClass("celulaEmEdicao");
$(this).html("<input type='text' value='" + conteudoOriginal + "' />");
$(this).children().first().focus();
$(this).children().first().keypress(function (e) {
if (e.which == 13) {
var novoConteudo = $(this).val();
$(this).parent().text(novoConteudo);
$(this).parent().removeClass("celulaEmEdicao");
$(this).parent().next();
};
});
$(this).children().first().blur(function(){
var novoConteudo = $(this).val();
$(this).parent().text(novoConteudo);
$(this).parent().removeClass("celulaEmEdicao");
$(this).parent().next();
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1" cellpadding="0" cellspacing="0" width="968" style="border-collapse:collapse;table-layout:fixed;width:734pt">
<tbody>
<tr class="item" style="text-align: center;">
<td class="cidade"></td>
<th style="text-align: center;">JAN</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
I wish that at the end of the typing the user had the possibility to move the cursor to the next <input type="text" />
of <td>
through a enter
or tab
, but I could not provide this functionality to the user.