获取鼠标选中文本内容

阅读更多
$(document).on('mouseup',function(){
    console.log(window.getSelection().toString());
});


补充:将选中内容标识出来
$(document).on('mouseup',function(e){  
        let a = document.createElement("span");
        a.setAttribute("class","wrap");
        window.getSelection().getRangeAt(0).surroundContents(a); 
    }); 


你可能感兴趣的:(JavaScript)