0
当我点击编辑按钮,并尝试编辑电子邮件列的内容.HTML表结构奇怪地改变。HTML contenteditable = true无序/改变表格行结构意外
这是我的代码片段:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<script>
function deleteAction(){
\t $("#fname").attr('contenteditable','true');
\t $("#lname").attr('contenteditable','true');
\t $("#email").attr('contenteditable','true');
}
</script>
<body>
<div class="container">
<table class="table table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
\t \t <th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td id="fname">John</td>
<td id="lname">Doe</td>
<td id="email">[email protected]</td>
\t \t <td><button class="btn btn-danger" id="delete" onclick="deleteAction()">Delete</button></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
这段代码与SO内嵌代码段亚军效果很好。但是您可以在下图中看到相同的代码工作方式不同。
谁能解决这个问题?并说我去哪里错了?
必须是一些其他脚本修改你的dom。它在jsfiddle中也能正常工作:https://jsfiddle.net/eqxdvxms/ – Liquidchrome
对于我来说,在内联snipper runner中工作不正常。 – Taurus