我的申请表上有以下代码段。在浏览器中,如果我在contenteditable div中使用退格键或删除键,它会删除文本旁边的注释,我需要阻止它。
段:
$(document).ready(function() {
$("#editedHTML").text($("#myEditor").html());
$("#save").click(function() {
$("#editedHTML").text($("#myEditor").html());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myEditor" contenteditable="true">
Hello World (press backspace after this)
<!-- This should not be removed -->
</div>
<br>
<button id="save">
Save
</button>
<br>Content to be saved:
<div id="editedHTML">
</div>