js获取选中的一段字符串并加标签
function surroundContent() {
        var r;
        if (document.selection) {
            r = document.selection.createRange();
            if (r.text != '') r.pasteHTML('' + r.text + '')
        }
        else if (window.getSelection) {
            r = window.getSelection();
            if (r.rangeCount > 0) {
                r = r.getRangeAt(0);
                var a = document.createElement('a');
                a.href = '#';
                r.surroundContents(a)
                r.collapse(false);
            }
        }
}
最后更新于 2017-03-17 15:58:08 并被添加「js」标签,已有 1446 位童鞋阅读过。
此处评论已关闭