私はテーブルを持っています:
<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);
});
これらはそれぞれ少しずつ異なることに注意してください - そして、私は過去何日もの間、他の多くのバリエーションを試してきました. 私が見つけたすべての例も見ましたが、何も機能していないようです。ヘルプ。ありがとう。リック