如何使用javascript从网页中获取单击或选择的文本?
如何使用javascript从网页中获取单击或选定的文本如何使用javascript从网页中获取单击或选择的文本?,javascript,jquery,google-chrome-extension,gettext,Javascript,Jquery,Google Chrome Extension,Gettext,如何使用javascript从网页中获取单击或选定的文本 如何获取手机号码或电子邮件等特定文本这应该适合您: const getSelectionText=()=>{ 让文本=”; if(window.getSelection){ text=window.getSelection().toString(); }else if(document.selection&&document.selection.type!=“控制”){ text=document.selection.createRan
如何获取手机号码或电子邮件等特定文本这应该适合您:
const getSelectionText=()=>{
让文本=”;
if(window.getSelection){
text=window.getSelection().toString();
}else if(document.selection&&document.selection.type!=“控制”){
text=document.selection.createRange().text;
}
返回文本;
}
请向我们展示您的html和代码。没有它真的很难给你一个好的答案