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()
精彩评论