简体   繁体   English

突出显示浏览器(Chrome)中的文本功能,看起来像在android中突出显示

[英]Highlight text feature in browser (Chrome) which looks like highlighting in android

I want to implement feature (for chrome extension) which allows the user to select some text from webpage in browser with mouse and I want to add ability for the user to edit selection boundaries (like it can be done in android application) with small controls below the selected line which can be moved with the mouse: 我想实现功能(用于chrome扩展),允许用户使用鼠标从浏览器的网页中选择一些文本,我想添加能力,用户可以通过小控件编辑选择边界 (就像可以在Android应用程序中完成)在可以用鼠标移动的选定行下方:

http://s17.postimg.org/9s9flupjj/android.png

May be there is existing library to achieve similar behaviour in browser in easy way? 可能有现有的库在浏览器中以简单的方式实现类似的行为吗?

i think this might help.. 我认为这可能会有所帮助..

var divs = document.getElementsByTagName("p");

for(var d in divs) {
  // highlight a part of a <p> tag
    divs[d].addEventListener('mouseup',function(){var str= document.getSelection()    ;alert(str);          
    this.innerHTML =this.innerHTML.replace(str,'<span style="background-color: '+'yellow'+' ">'+str+'</span>');
    }); 
}

And more of it can be found in here 其中更多内容可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM