次の形式の入力フィールドを含む一連のスパンから配列を生成する方法はありますか?
[[1,100],[2,200],[3,300],[4,400]]
HTML:
<div id="arrays">
<span>
<input type="text" value="1">
<input type="text" value="100">
</span>
<span>
<input type="text" value="2">
<input type="text" value="200">
</span>
<span>
<input type="text" value="3">
<input type="text" value="300">
</span>
</div>
私は成功せずにこのようにそれに取り組みました:
str = [];
$('#arrays').children("span").find('input').each(function(index) {
str[index] = $(this).val();
});
var string = [ str ];
次に、配列は次のようにjqPlotに渡されます。
var plot1 = $.jqplot('chartdiv', [string]);
配列を生成しない場合、コードは次のようになります(例)。
var plot1 = $.jqplot('chartdiv', [[[1,100],[2,200],[3,300]]]);