JavaScript 突出显示所有div(bookmarklet)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 突出显示所有div(bookmarklet)相关的知识,希望对你有一定的参考价值。

javascript:/*Highlight_all_DIVS.js*/(function(){var styleId='ujs_display_div_order'; var className='ujs_display_div_order_details'; function addStyle(){var s=document.getElementById(styleId); if(s){clean(); s.parentNode.removeChild(s); return false;} var s=document.createElement('style'); s.id=styleId; s.setAttribute('type', 'text/css'); s.setAttribute('style', 'display:none !important;'); s.appendChild(document.createTextNode('span.'+ className + ' {color: #000 !important; background: #ffff99 !important; border: 1px solid #ffcc66 !important; display: inline-block !important; font-family: sans-serif !important; font-size: 10px !important; font-style: normal !important; font-variant: normal !important; font-weight: normal !important; letter-spacing: 0 !important; margin: 0 1px 0 0 !important; padding: 1px !important; text-align: left !important; text-decoration: none !important; text-transform: none !important; z-index: 1 !important; opacity: 0.9 !important;} div {outline: 1px solid #ff0000 !important;}')); document.documentElement.appendChild(s); return true;} function clean(){var s=document.selectNodes('//span[@class=\'' + className + '\']'); for(var i=0; i<s.length; i++){s[i].parentNode.removeChild(s[i]);}} function display(){if(!addStyle()){return;} var d=document.getElementsByTagName('div'); for(var i=0; i<d.length; i++){var t='div'; t+=d[i].id ? (' #'+d[i].id) : ''; t+=d[i].className ? (' .'+d[i].className) : ''; t+=' '+(i + 1).toString(); var s=document.createElement('span'); s.className=className; s.title=t; s.innerText=t; d[i].insertBefore(s,d[i].firstChild);}} display();})();

以上是关于JavaScript 突出显示所有div(bookmarklet)的主要内容,如果未能解决你的问题,请参考以下文章

从文本输入中突出显示 div 中的所有匹配单词

突出显示具有相同类的所有 div

切换 div 并突出显示当前菜单项

突出显示文本功能,如 google play book

单击鼠标选择所有 DIV 文本

浏览器内文本的交互式选择突出显示