如何在粘贴到contenteditable和sanitization后恢复光标位置?

时间:2012-04-21 11:51:57

标签: javascript cursor copy-paste contenteditable sanitize

我的<div>contenteditable="true",粘贴后我正在使用Sanitize.js清理粘贴的内容。当然,问题是在Sanitization之后光标放在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);
}

0 个答案:

没有答案