我需要解决这个问题......因为这很烦人,因为每 1000 毫秒就会发生一次!!!
这是完整的代码:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>
function insertTextAtCursor() {
var sel, range, html;
if (window.getSelection) {
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode( document.createTextNode('567') );
}
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().text = text;
}
}
</script>
<div contenteditable onclick="insertTextAtCursor()">hi</div>
<script>
setInterval(function() {
$("body").html($("body").html().replace(/567/g,'<b>abcde-fghi</b>'));
},1000);
</script>