开发者

jquery gt() get current index

I'm using gt() 开发者_JAVA百科to add columns to a table.

I need to use the row number and the column number to build the cell id.

Getting the column number is straightforward:

var c = $("#gridLayout tr:first td").length;

but how can I get the current index from gt() for the row number?

$("#gridLayout tr:gt(0)").append('<td>.......</td>');


One way would be to use the built in index parameter for .each().

This lets you get an index number without having to call another method.

Try it out: http://jsfiddle.net/8V4AY/

   // Reference index --------------v
$("#gridLayout tr").each(function( idx ) {
       // idx contains the current index number,
       //    without having to call another method

     $(this).append('<td>.......</td>');
});

If you were going to skip the first row:

$("#gridLayout tr:gt(0)")...

you could adjust the idx by 1 if you need

idx++;

http://jsfiddle.net/8V4AY/1/


Im not really sure what your goal here is but something similar to the following would return the row index and append whatever contents:

$('#gridlayout tr').each( function() {
    $(this).append('<td> Things.... </td>');
    alert($(this).index());
})

If you post some more details I will gladly provide further info.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜