不用这么麻烦的,只要一段JS就可以了,不过你要先在文章内容所在的DIV或是TD里加入:class="newstext-box",然后在关键字出现的DIV或是TD里加入:class="keywords-box" 再在内容模板下方加入这一段就可以了: <style> .newstext-box a{color: #006ad3} </style> <script>document.addEventListener("DOMContentLoaded",function(){const e=document.querySelectorAll(".keywords-box a"),t=document.querySelector(".newstext-box");if(!e.length||!t)return;let r=t.innerHTML;const n=new Set;e.forEach(a=>{const c=a.textContent.trim(),l=a.getAttribute("href");if(n.has(c))return;const o=new RegExp(`(?<!["'>])(${c})(?![^<]*>|[^<>]*</a>)`);o.test(r)&&(r=r.replace(o,`<a href="${l}" class="highlight-keyword" target="_blank">$1</a>`),n.add(c))}),t.innerHTML=r});</script>
|