<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");})
精彩评论