Select Text & highlight selection or get selection value (React)

后端 未结 6 1241
长发绾君心
长发绾君心 2021-02-02 02:33

I have a React application which displays some spans:

Hello my name  is &l         


        
6条回答
  •  广开言路
    2021-02-02 02:51

    Step 1: - Initially Mouse will capture every time you enter something

    
    

    Step 2: To make sure it only catches your selected text I used if-else condition

    selectedText = () => {
        window.getSelection().toString() ? console.log(window.getSelection().toString()) : null;
    }
    

提交回复
热议问题