如何获取每行中单击的值(使用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]").click(function()
{
$("input[name=textfield]").val($(this).text());
return false;
});
但是不要让它适用于不同的文本域。
有任何想法吗?
好的,我有
$("a[class=autofill]").live("click", function(){
$("input[name=textfield1]").val($(this).text());
return false;
});
但我如何调整它以使其为每一行动态。我们说textfield1,textfield2,textfield3等等。
我只是快速浏览一下,但我想可能click()
对定义click事件后使用的元素没有生效。试试live()
:$("a[class=autofill]").live("click", function(){ ... });