我正在尝试开发一个jQuery插件。这是我的第一个插件,我在初始阶段遇到了困难。
我需要做以下几件事:我需要从表格中找到“添加行”链接并绑定到单击事件。当单击链接时,它应该通过克隆现有的模板行来添加新行。初始时模板行是隐藏的。
以下是HTML代码:
<table id='grid1'>
<tr>
<td><a href='#' id='add_row'>Add New Row</a></td>
</tr>
<tr>
<td>
<table id='data_table'>
<tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
<tr><td>Data1</td><td>Data2</td><td>Col3</td></tr>
<tr id='template_row'>
<td><input type='text' /></td>
<td><input type='text' /></td>
<td><input type='text' /></td>
</tr>
</table>
</td>
</tr>
</table>
我的jQuery代码如下:
(function($) {
$.extend($.fn, {
editableGrid: function() {
function addRow() {
//code to clone here but i need the instance of main table here ie grid1
}
this.find('#add_row').bind("click",addRow);
}
});
})(jQuery);