javascript - HTML contenteditable=true 乱序/意外改变表格行结构

标签 javascript jquery html css contenteditable

当我单击编辑按钮并尝试编辑电子邮件列的内容时。HTML 表格结构发生了奇怪的变化。

这是我的代码片段:

<!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(){
	$("#fname").attr('contenteditable','true');
	$("#lname").attr('contenteditable','true');
	$("#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>
		<th>Delete</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="fname">John</td>
        <td id="lname">Doe</td>
        <td id="email">john@example.com</td>
		<td><button class="btn btn-danger" id="delete" onclick="deleteAction()">Delete</button></td>
      </tr>
    </tbody>
  </table>
</div>

</body>
</html>

此代码片段适用于 SO 内联代码片段运行器。但是您可以在下图中看到相同的代码以不同的方式工作。

enter image description here

谁能解决这个问题?告诉我哪里错了?

最佳答案

调试代码后,我了解到我的 chrome 浏览器中的 Grammarly 扩展导致了这个问题。禁用扩展后,它工作正常。

关于javascript - HTML contenteditable=true 乱序/意外改变表格行结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46242234/

相关文章:

javascript - 悬停时显示 div 的问题

javascript - 如何读取 Angular 模块中的 json 配置文件?

javascript - jQuery 第 n 个子项中的每个 div

jquery - 销毁 jQuery Flot 图表

Javascript 自定义用 "Yes"或 "No"确认

php - 将 HTML 页面保存到 MySQL 数据库,然后将代码插入该 HTML 并再次提供服务

javascript - OpenLayers.source 未定义 - 打开图层,打开街道 map

javascript - 如何在 D3.js 中添加地理链接(创建为 json 路径)?

javascript - 强制浏览器记住选择框中的选项

jquery - 使用 jQuery 在单击时交换 CSS 背景图像