我在使用jQuery clone时尝试将jQuery AutoComplete应用于表中的多行时遇到问题.AutoComplete在第一行上工作,但在向表中添加其他行时无法工作.到目前为止,我有以下内容:
HTML表格:
<table class="table" cellspacing="0" id="myTable">
<tr>
<th width="40%">Item</th>
<th width="60%">Description</th>
</tr>
<tr>
<td>input name="product_title" id="product_title" type="text"><td>
<td><textarea name="product_description" id="product_description"></textarea></td>
</tr>
</table>
<input type="button" value="Add Row" onclick="javascript:addRow()">
Run Code Online (Sandbox Code Playgroud)
克隆脚本:
function addRow(){
$('#myTable tr:last').clone(true).insertAfter('#myTable tr:last');
$('#myTable tr:last input').val("");
$('#myTable tr:last input:first').focus();
}
Run Code Online (Sandbox Code Playgroud)
自动完成脚本:
$().ready(function() {
$("#product_title").autocomplete(products, {
width: 380,
matchContains: "word",
formatItem: function(row) {
return row.title;
}
});
$('#product_title').result(function(event, data) {
$('#product_description').val(data.description);
});
});
Run Code Online (Sandbox Code Playgroud)
自动完成的数据来自简单的MySQL查询,该查询定义了产品标题和描述.
目前,添加新行工作正常,表的第一行的自动完成也是如此,但是它无法处理添加的任何其他行.即使我手动向HTML表添加第二行,自动完成也不会对此有效.
有没有人知道是否有一种(简单的)方法来修改上面的代码以使其工作?对于jQuery来说我是新手所以越多细节就越好.
提前致谢!!!