扫码关注官方订阅号
title this is a test.this is a test
this is a test.this is a test
诸如以上代码,如何能匹配title文本中的is关键字,并使之在网页中反色显示。 PS:我想可以找到关键字,然后给关键字的文本对象加入一个CSS 样式,比如is,但我又不知如何动手。
title
is
CSS 样式
小伙看你根骨奇佳,潜力无限,来学PHP伐。
var html = $('#title').html(); html = html.replace(/is/g, '<span class="guanjianzi">is</span>'); $('#title').html(html);
var el = document.getElementById('title'); el.innerHTML = el.innerHTML.replace(/is/g, '<span class="guanjianzi">is</span>');
找到一个很棒的 jQuery 插件,可以这样进行高亮:$('#title').highlight('is');Source
$('#title').highlight('is');
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
找到一个很棒的 jQuery 插件,可以这样进行高亮:
$('#title').highlight('is');Source