【发布时间】:2016-01-31 08:38:30
【问题描述】:
经过深入研究,我能够在我的表格中编辑和更新一个数据值。但是,当我尝试更改可以编辑 contenteditable 的位置时,它会删除我的表格格式(它实际上完全删除了表格格式,使我的想法毫无意义。
这是我当前的代码。
<div class="bs-docs-example">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>IRC Name</th>
<th>Ingame Name</th>
<th>Position</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>[Cr|m|nAl]</td>
<td id="content2" contenteditable="true">Herbalist</td>
<td>Aeterna Top</td>
</tr>
<tr>
<td >2</td>
<td >bandido</td>
<td >Bananni</td>
<td >Aeterna Top</td>
</tr>
<tr>
<td>3</td>
<td>Funkystyle</td>
<td>Funkystyle</td>
<td>Aeterna Top</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<button id="save">Save Changes</button>
<!-- begin the script -->
<script src="js/jquery.js" type="text/javascript"></script>
<script>
var theContent = $('#content2');// set the content
$('#save').on('click', function () { // store the new content in localStorage when the button is clicked
var editedContent = theContent.html();
localStorage.newContent = editedContent;
});
if (localStorage.getItem('newContent')) { // apply the newContent when it is exist ini localStorage
theContent.html(localStorage.getItem('newContent'));
}
</script>
现在,理想情况下,我希望它像下面的屏幕截图一样输出; http://i.imgur.com/R4TYhRB.png “游戏内名称”栏可编辑。 Add Row/Remove Row,我也想实现,但我不太确定你能不能用这么简单的HTML表格来实现。
我的第一个问题- 我如何使特定行(即游戏名称)成为唯一可编辑的行?我的 Javascript/Jquery 很糟糕,不幸的是,我的研究只允许我改进一行。 (我知道我可能可以复制 javascript/jquery,但肯定有更简单的方法吗?)
第二个问题-
是否可以在没有某种数据库的情况下为 HTML 表添加添加/删除行的功能?
感谢您对此的任何指导。
【问题讨论】:
-
你能在 jsfiddle 中添加它吗?这样我们就可以更好地了解您使用了哪些资源。
-
jsfiddle.net/3enz61xy JS 小提琴。我想编辑所有游戏名称行。
标签: javascript jquery html html-table