开发者

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

开发者 https://www.devze.com 2023-02-01 02:43 出处:网络
<table id =\'t1\'> <tr val=\'1\'></tr> <tr val=\'2\'></tr> <tr val=\'3\'></tr>
<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

精彩评论

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