gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:00:25 26 4
gpt4 key购买 nike

当我单击编辑按钮并尝试编辑电子邮件列的内容时。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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com