无法编辑添加的新行
New row added can't be edited
我正在使用codeigniter和bootstrap-editable.js等作为插件。我用空值制作了一个可编辑的表。我只显示一行,如果用户想要添加新行,我创建了一个添加按钮。addnew 按钮有一个鼠标单击事件,它会自动添加一个空的新行。我希望新添加的行也是可编辑的。.但就像我的情况/代码一样,它不起作用。
这是我的代码:
<table class="table " id="memberTB">
<thead><tr><th >First Name</th><th >Middle Name</th><th>Last Name</th></tr></thead>
<tbody>
<tr><td><span class="edit"></span></td>
<td><span class="edit"></span></td>
<td><span class="edit"></span></td></tr>
</tbody>
<button type="button" class="btn btn-link" id="addrow"><span class="fa fa-plus"> Add new row</span></button>
</table>
这是Javascript代码:
$.fn.editable.defaults.mode = 'inline';
$.fn.editable.defaults.showbuttons = false;
$.fn.editable.defaults.url = '/post';
$.fn.editable.defaults.type = 'text';
// make all items having class 'edit' editable
$('.edit').editable();
//ajax emulation
$.mockjax({
url: '/post',
responseTime: 200,
response: function(settings) {
console.log('done!');
}
});
// this is to automatically make the next item in the table editable
$('.edit').on('save', function(e, params){
var that = this;
// persist the old value in the element to be restored when clicking reset
var oldItemValue = $(that)[0].innerHTML;
if (!$(that).attr('oldValue')) {
console.log('persisting original value: ' + oldItemValue)
$(that).attr('oldValue', oldItemValue);
}
setTimeout(function() {
// first search the row
var item = $(that).closest('td').next().find('.edit');
console.log(item);
if (item.length == 0) {
// check the next row
item = $(that).closest('tr').next().find('.edit');
}
item.editable('show');
}, 200);
});
$('#addrow').click(function() {
$('#memberTB > tbody:last').append(' <tr><td><span class="edit"></span></td><td><span class="edit"></span></td><td><span class="edit"></span></td></tr>');
});
如何使新添加的行可编辑?请帮助我..
在您的$('#addrow').click(function() {});
中,我会添加以下内容:
$('.edit').off();
$('.edit').fn1();
$('.edit').fn2();
fn1
和fn2
是已经绑定到edit
类的任何函数(即 .editable 和 .on)
这会将函数重新绑定到所选元素,但首先删除绑定,以便元素不会获得双重(或三重等)绑定。
相关文章:
- 拆分文本以每隔n个字符添加一行新行,并注意空格
- 如何在脚本上添加新行
- 在不刷新整个网格的情况下,向Asp.net网格视图添加新行
- dhtmlx添加新行并启动单元格编辑器
- 在新行(html)中动态添加更多文本字段
- 如何在Google Geochart图表的工具提示文本中添加新行
- 为什么要将此p标记添加为新行
- Jquery在表WITH函数中追加新行后添加单击事件
- 无法编辑添加的新行
- 如何在javascript中每次添加新行时都增加ordre值
- 将新行添加到localStorage变量中
- 当上一行/当前行被填充时,将新行添加到HTML表中
- 当新行添加到表中时,使用AJAX更新页面
- 将新行添加到数据库时的 Javascript 警报
- 为 HTML 文本区域中的新行添加效果
- 将新行添加到空的剑道网格中
- 单击按钮时,将新行添加到包含下拉列表的表中
- 向输出空间或新行添加新行或空格
- 使用2下拉列表将新行添加到表中-如何更改选择的名称
- 为按钮创建的每个新行添加i++