简体   繁体   English

jQuery td内联编辑->输入后进入下一个编辑单元格?

[英]JQuery td inline edit -> after enter go to next edit cell?

I am using the code below to insert a edit box, and on enter save the result to MySQL database which is working perfectly 我正在使用下面的代码插入一个编辑框,并在输入时将结果保存到运行良好的MySQL数据库中

The table cells to edit look like 要编辑的表格单元格看起来像

<tr><td class="edit tbl_tracking 92"></td></tr>
<tr><td class="edit tbl_tracking 96"></td></tr>
<tr><td class="edit tbl_tracking 101"></td></tr>

After pressing enter and the save is complete I want to automatically select the next edit box with it being focused. 按Enter键并完成保存后,我要自动选择下一个具有焦点的编辑框。 So after each entry after pressing enter the next one down is selected and focused. 因此,在按回车键后的每个条目之后,将选择下一个并确定焦点。 There are other cells in each row but have now div or edit required I cannot work out to to get it working and have looked everywhere 每行中还有其他单元格,但现在需要进行div或编辑操作,我无法工作以使其正常运行并且四处查看

Any help would be great. 任何帮助都会很棒。

$(document).ready(function () {
        $('td.edit').click(function () {
            $('.ajax').html($('.ajax input').val());
            $('.ajax').removeClass('ajax');
            $(this).addClass('ajax');
            $OLDVAL = $(this).text();
            $(this).html('<input id="editbox" size="20" type="text" 
                                    value="' + $(this).text() + '">');
            $('#editbox').focus();
        });

        $('td.edit').keydown(function (event) {
            arr = $(this).attr('class').split(" ");
            if (event.which == 13) {
                $.ajax({
                    type: "POST",
                    url: "ajaxpost.php",
                    data: "value=" + $('.ajax input').val() + "&rownum=" 
                                               + arr[2] + "&field=" + arr[1],
                    success: function (data) {
                        $('.ajax').html($('.ajax input').val());
                        $('.ajax').removeClass('ajax');
                    }
                });
            }
        });

        $('#editbox').live('blur', function () {
            $('.ajax').html($('.ajax input').val());
            $('.ajax').html($OLDVAL);
            $('.ajax').removeClass('ajax');
        });
    });

you may try to bind a keydown event to the edit box input. 您可以尝试将keydown事件绑定到编辑框输入。 On key down, it should fire the click event of the next cell. 按下按键时,它将触发下一个单元格的click事件。

$('#editbox').keydown(function(event){
if (event.which == 13)$(this).parent().parent().next().children(':first').trigger('click');
});

hope this is helpful 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM