开发者

get an array of "val" attributes values from the rows of a table

<table id ='t1'>
<tr val='1'></tr>
<tr val='2'></tr>
<tr val='3'></tr>
<tr val='4'></tr>
<tab开发者_JS百科le>

how to get from this an array = 1,2,3,4


You can use .map(), like this:

var arr = $("#t1 tr").map(function() { return $(this).attr("val"); }).get();

You can test it out here.


This should work:

$.map( $( "table#t1 tr"), function( item) { return $(item).attr("val");})
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜