OKだから、フォームの送信ボタンをクリックした後に、次のhtmlテーブルをページに出力するajax関数があります。
<table id="assetAllocation">
<thead>
<tr>
<th></th>
<th>Protector</th>
<th>Balanced</th>
<th>Progressive</th>
</tr>
</thead>
<tbody>
<tr>
<th class="theading">Cash</th>
<td>15.69</td>
<td>18.43</td>
<td>15.40</td>
</tr>
<tr>
<th class="theading">Equities</th>
<td>30.54</td>
<td>43.18</td>
<td>54.90</td>
</tr>
<tr>
<th class="theading">Fixed Income</th>
<td>23.31</td>
<td>14.49</td>
<td>8.00</td>
</tr>
<tr>
<th class="theading">Hedge Fund</th>
<td>0.40</td>
<td>4.94</td>
<td>4.98</td>
</tr>
<tr>
<th class="theading">Commodities</th>
<td>2.36</td>
<td>3.73</td>
<td>3.56</td>
</tr>
<tr>
<th class="theading">Other</th>
<td>27.70</td>
<td>15.22</td>
<td>13.16</td>
</tr>
</tbody>
</table>
また、ページの下部で定義した次のハイチャート関数もあります。
function assetChart() {
$('#assetChart').highcharts({
data: {
table: document.getElementById('assetAllocation')
},
chart: {
type: 'column'
},
title: {
text: 'Data extracted from a HTML table in the page'
},
yAxis: {
allowDecimals: false,
title: {
text: 'Units'
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.y +' '+ this.x.toLowerCase();
}
}
});
}
さらに、ページの静的 html の一部として this html があります。
<a href="#" id="clicker">Click me</a>
<div id="assetChart"></div>
<script>
$(function () {
$('#clicker').click(function(){assetChart()});
});
</script>
AJAX で読み込まれたテーブルが上記で生成されたら、[クリックしてください] リンクをクリックすると、assetChart
コンテナー内のグラフにデータが表示されます。ただし、これは機能していません。実際には何も起こりません - JavaScript エラーはログに記録されません。getElementById
AJAX で生成されたコンテンツの選択に使用できますか? 私のコードの何が問題なのか誰にもわかりますか?