我的<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);
}