3

我有一个<div>contenteditable="true"粘贴后我正在使用Sanitize.js 清理粘贴的内容。当然,问题是在消毒之后,光标放在了 div 的开头。如何在粘贴的内容之后放置光标位置?

HTML: <div contentEditable="true" id="ce"></div>

来自 Sanitize.js 示例的 JS(已修改):

function do_sanitize(){
    var elm = document.getElementById('ce');
    var cfg = Sanitize.Config.RELAXED;
    // Create new Sanitize object
    var s = new Sanitize(cfg);
    var cleaned_html = s.clean_node(elm);
    // Prepare container for sanitized HTML and append it
    var clean_container = document.getElementById('ce');
    while(clean_container.childNodes.length > 0) {
    clean_container.removeChild(clean_container.firstChild);
  }
  clean_container.appendChild(cleaned_html);
}
4

0 回答 0