各行でクリックされた値 (AddRowTable プラグインを使用して生成) を取得するにはどうすればよいですか?
<script type="text/javascript">
$("document").ready(function(){
$(".addRow-Max4").btnAddRow({maxRow:4, inputBoxAutoNumber:true});
$(".delRow").btnDelRow();
});
</script>
テーブル内に最大 4 行を生成し、各入力ボックスに番号を付けるので、テーブル内に textfield1、textfield2 などを取得します。
<table border="0" >
<tr>
<th colspan="2">Input your data</th>
<th><input type="button" value="Add Row" class="addRow-Max4"/></th>
</tr>
<tr><td>
<a href="#" class="autofill">Apple</a>
<a href="#" class="autofill">Banana</a>
<a href="#" class="autofill">Mango</a>
</td><td><input type="text" name="textfield" class="autofill" size="25"/></td>
<td><img src="./images/cross.gif" class="delRow" border="0"></td>
</tr>
</table>
ここで、行 1 に Apple、行 2 にマンゴーなどを決定し、この行に対応するテキスト フィールドが入力されるようにします。
私は持っている
$("a[class=autofill]").live("click", function(){
$("input[name=textfield1]").val($(this).text());
return false;
});
しかし、行ごとに動的にするためにどのように調整する必要がありますか。textfield1、textfield2、textfield3 などとしましょう。今のところ、リンクがクリックされるたびに textfield1 を変更しています。しかし、対応する(同じ行の)リンクの1つがクリックされた場合に変更したいだけです。