【发布时间】:2012-02-28 18:01:39
【问题描述】:
如何获取每行中点击的值(使用 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>
现在我可能决定在 row1 中使用 Apple,在 row2 中使用 Mango 等等,并希望填充该行的相应文本字段。
我有
$("a[class=autofill]").live("click", function(){
$("input[name=textfield1]").val($(this).text());
return false;
});
但是我必须如何调整它以使其对每一行都是动态的。比方说 textfield1、textfield2、textfield3 等等。就像现在一样,每次单击链接时我都会更改 textfield1 。但是,如果单击相应的(同一行)链接之一,我只想更改它。
【问题讨论】:
标签: jquery html-table autofill