开发者

JQuery + table issue with IE

I have a dynamic table with a delete button an开发者_StackOverflowd several input elements on each row. Each row has an ID. When i push the delete button I use jQuery to delete the row and then update the ID's. Like this

function deleteRow(row) {
    var num = $("#table>tbody>tr").length;
    if (num > 1) {
        $(row).closest("tr").remove();
    }
    updateIds();
}

function updateIds() {
        var counter = 0;
        var num = $("#myTable>tbody>tr").length;
        $("#myTable>tbody>tr").each(function(){
            $("input",this).each(function(){
                var currentId = $(this).attr("id");
                var newId = currentId.substring(0,currentId.indexOf(('_'))+1);
                $(this).attr("id",newId+counter);
                var currentPath = $(this).attr("name");

                var front = currentPath.substring(0,currentPath.indexOf('[')+1);
                var back = currentPath.substring(currentPath.indexOf(']'));

                $(this).attr("name",front+counter+back);

            })

            counter++;
        })
    }

This works Fine in FF and Chrome but in IE 7 I am having some trubble after running these two functions. When i focus on an input element in a tr the cursor jumps up one row. Its like its trying to fucus on the tr that was just deleted.

Anybody have any ideas


Well, you can manually set the focus with:

$(element).focus();

Get the element using the index of the row/cell you want the focus to be. Does that help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜