Get the text content selected by the mouse

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


Supplement: Mark the selected content
$(document).on('mouseup',function(e){  
        let a = document.createElement("span");
        a.setAttribute("class","wrap");
        window.getSelection().getRangeAt(0).surroundContents(a);
    });


<style>
    span.wrap{background:goldenrod;}
</style>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326541563&siteId=291194637