我解析了 JSON 对象并制作了一个表结构来显示元素。我想让表格的行可编辑。这是我用来形成表格的代码。
(jsonDatag.data).forEach(function(item) {
var _tr = '<tr class="' + item.symbol + '"><td>' + item.symbol + '</td><td class="' + hclass + '">' + item.highPrice + '</td><td class="' + lclass + '">' + item.lowPrice + '</td><td class="' + oclass + '">' + item.openPrice + '</td><td class="' + ltclass + '">' + item.ltp + '</td><td>' + item.previousPrice + '</td><td>' + item.lastCorpAnnouncementDate + '</td></tr>'
_tbody += _tr
});
_thead = _thead + _tbody;
$('.mytable').html(_thead)
}
现在我添加了这些行以使我的行可编辑,但它没有反射(reflect)在我的输出中。
$('tr.'+item.symbol+'').each(function() {
$(this).html('<input type="text" value="' + $(this).html() + '" />');
});
这里出了什么问题,我该如何纠正?
最佳答案
Editable rows is not working in table
这似乎令人困惑,因为它是可编辑的 td
。
还有这个片段
$('tr.' + item.symbol + '').each(function() {
$(this).html('<input type="text" value="' + $(this).html() + '" />');
});
可能会放置一个输入
。
如果你想制作一个可编辑的td
那么
<td contenteditable="true">
会起作用
关于javascript - 可编辑行在包含 JSON 数据的表中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38367719/