从tr开始引用时,如何获取td中画布的上下文?示例代码:jquery,从tr获取画布上下文
<table>
<tr name='pool_row' id='swimming_pool'>
<td>
</td>
<td>
</td>
<td name='write_graphic'>
<canvas name='graphic' class='dataset_graphic' width='200' height='23'></canvas>
</td>
<td name='read_graphic'>
<canvas name='graphic' class='dataset_graphic' width='200' height='23'></canvas>
</td>
</tr>
<tr name='pool_row' id='hot_tub'>
<td>
</td>
<td>
</td>
<td name='write_graphic'>
<canvas name='graphic' class='dataset_graphic' width='200' height='23'></canvas>
</td>
<td name='read_graphic'>
<canvas name='graphic' class='dataset_graphic' width='200' height='23'></canvas>
</td>
</tr>
</table>
<script>
$("tr[name='pool_row']").each(function(){
//Get Data for all pools from DB
//Loop over them, when match is found
//by id draw something.
var ctx = $(this).find("td[name='write_graphic']").find("canvas").getContext('2d');
});
</script>
显然,真正的PHP生成的表我的工作是一个复杂得多。所有这些也都在setInterval函数中进行,因此它每隔1秒发生一次......但它不适用于该问题,只是它的重要性。
取决于示例HTML的代表性。其他行的构造是否相同?如果不是,可能会有什么变化? –
有三种类型的行,pool_row是第一种类型......其他两种类型将有不同的代码,但行几乎相同。只有pool_row类型会受到这个特定选择器的影响。将会有多个池行,并且td的数量会随着设计的进展而变化,所以我想按名称来做......会让jquery变得更小。所有游泳池行将被构造相同,并具有不同的值。 – gunslingor