ダブルクリックしたときに特定のIDのtd値を編集したい。ロジックを書きました。以下のコードの「get()」関数は、テーブル td に割り当てられた 10 個のステータスを返します。任意のステータスをダブルクリックすると、インプレース編集と保存の機能が必要になります。しかし、なぜそれが機能していないのかわかりません。誰か助けてください。
<html>
<head><title></title></head>
<body>
<div id="body" >
</div>
</body>
</html>
<script>
$(document).ready(function(){
var table='<table>';
table += '<tr><th style=""> Status</th></tr>';
table += '</table></br>';
$("#body").append(table);
var $tbody = $('<tbody>').appendTo('#body table:last');
$.ajax({
type : 'POST',
url : '@routes.Application.get()',
data : {
itemupc : item[0]
},
beforeSend:function()
{
},
success : function(items) {
$.each(items, function(j, itemsdetails) {
if(itemsdetails[3]=="R")
$tbody.append('<tr><td id="my'+itemsdetails[0]+'" class="editableTD">0</td></tr>');
});
}
});
$("#item_content").on('dblclick','.editableTD',function(e){ //assign event to editableTD class
e.stopPropagation();
var currentID=$(this).attr("id"); //grab the current id instead
var currentValue= $(this).html();
inlineEditSave(currentID,currentValue);
});
function inlineEditSave(currentElement,currentValue)
{
//$(currentElement).html('<i class="fa-li fa fa-spinner fa-spin"></i>');
$(currentElement).html('<input type="text" class="thVal" value="' + currentValue + '" />');
$(".thVal").focus();
$(".thVal").keyup(function (event) {
if (event.keyCode == 13) {
$(currentElement).html($(".thVal").val().trim());
}
});
$(document).click(function () {
$(currentElement).html($(".thVal").val().trim());
});
}
});
</script>