1

ダブルクリックしたときに特定の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>
4

1 に答える 1

4

Font Awesome を使用している場合、ブートストラップを使用していると仮定できますか? もしそうなら、ロジックを自分でコーディングしている特定の理由はありますか? x-edtiable と呼ばれるこのためのライブラリがあり、すべての面倒な作業を処理します。

http://vitalets.github.io/x-editable/

デモ/使用例は次の場所にあります。

http://vitalets.github.io/x-editable/demo-bs3.html

于 2014-05-19T04:45:12.863 に答える