我有一张桌子:
<table width="160" align="center" id="my_table">
<tbody>
<tr>
<td><img src="Color1.png" width="160" height="40" alt="1"></td>
</tr>
<tr>
<td><img src="Color2.png" width="160" height="40" alt="2"></td>
</tr>
<tr>
<td><img src="Color3.png" width="160" height="40" alt="3"></td>
</tr>
</tbody>
</table>
我允许用户上下移动颜色块 - 有更多颜色。在过程结束时,我想知道每个 alt 的位置(哪个子位置),并使用 jQuery 将其保存到单独的变量中。我试过了:
$('#my_table').on('click', 'img', function() {
var color_rated_1 = $("#my_table.tr:nth-child(1)");
alert("color_rated_1 is " + color_rated_1);
});
$('#my_table').on('click', 'img', function() {
var color_rated_2 = $(".tr:nth-child(2)");
alert("color_rated_2 is " + color_rated_2);
});
$('#my_table').on('click', 'img', function() {
var color_rated_3 = $("#my_table tr:nth-child(3)");
alert("color_rated_3 is " + color_rated_3);
});
请注意,每一个都有点不同——在过去的很多天里,我尝试了许多其他的变化。我还查看了我找到的所有示例,但似乎没有任何效果。帮助。谢谢。瑞克