开发者

getting values from an array (JS / jQuery)

I'm passing an array to a function I want to be able to show or hide columns in a table depending on what's passed.

So, if I pass 1,3,4 columns 1 3 and 4 should show - column 2 should not.

I can handle the show/hide bit. 开发者_C百科I'm just not sure how to grab the values from the array


A simple loop that looks at all the values. jQuery can use the nth-child selector to get the n-th item in a group. Not sure about the selector, but use [] notation to get the values:

var i = 0;
for(i = 0; i < array.length; i++) {
    $('tr td:nth-child(' + array[i] + ')').hide();
}

EDIT

changed the :eq to :nth-child()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜