当前位置: 首页 > news >正文

高亮匹配关键词样式highLightMatchString、replaceHTMLChar

 

    replaceHTMLChar: s => s.toString().replace(/</g, `&lt;`).replace(/>/g, `&gt;`),// 高亮匹配关键词样式----------------------------------------highLightMatchString(originStr, matchStr, customClass = ``) {matchStr && (matchStr = matchStr.replace(/[.*+?^${}()|[\]\\]/g, ``));//过滤掉字符串里面的出现的正则表达式字符if (matchStr === ``) return originStr;customClass === true && (customClass = `sg-search-word-highlight`);let newRepStr = (match = matchStr) => customClass ? `<span class=${customClass}>${this.replaceHTMLChar(match)}</span>` : `<b style='color:red;font-weight:bold;'>${this.replaceHTMLChar(match)}</b>`;// return this.replaceHTMLChar(originStr).replace(new RegExp(this.replaceHTMLChar(matchStr), `gi`), newRepStr(matchStr));return this.replaceHTMLChar(originStr).replace(new RegExp(this.replaceHTMLChar(matchStr), `gi`), (match, index) => newRepStr(match));// 返回原始匹配项,如果不希望替换,可以返回match},

http://www.lryc.cn/news/596959.html

相关文章:

  • Effective Python 第15条 不要过分依赖给字典添加条目时所用的顺序
  • CodeBuddy IDE实战:用AI全栈能力快速搭建课程表网页
  • JavaScript HTTP 请求:从老古董到新潮流
  • 在线深凹槽深检测方法都有哪些 —— 激光频率梳 3D 轮廓检测
  • 如何在Pico等Android头显中实现无人机低延迟RTMP全景巡检画面播放
  • 2025年7月份实时最新获取地图边界数据方法,省市区县街道多级联动【文末附实时geoJson数据下载】
  • 从零开始学习Dify-Excel数据可视化(四)
  • 无人机光伏巡检误检率↓78%!陌讯多模态融合算法实战解析
  • 【Android】用 ViewPager2 + Fragment + TabLayout 实现标签页切换
  • Android用户鉴权实现方案深度分析
  • react18更新哪些东西
  • Nginx和Apache的区别
  • Apache PDFBox深入实践
  • Apache JMeter 使用记录踩坑
  • MCP客户端架构与实施
  • Apache POI 介绍与使用指南
  • apache-doris安装兼datax-web配置
  • LNMP-zblog分布式部署
  • 【Unity Shader】Special Effects(十二)Glow 外发光(UI)
  • Unity × RTMP × 头显设备:打造沉浸式工业远控视频系统的完整方案
  • 如何在macOS上修改iPhone的定位
  • ESP32的ADF详解:5. Streams的API
  • 聊聊 Flutter 在 iOS 真机 Debug 运行出现 Timed out *** to update 的问题
  • 在AI深度嵌入企业业务的当下——AI时代的融合数据库
  • Qt 菜单与工具栏设计:提升用户体验
  • AI产品经理面试宝典第48天:产品设计与用户体验优化策略
  • 【数学建模 | Matlab】二维绘图 和 三维绘图
  • 国产数据库转向 “融合” 赛道:电科金仓的下一代形态定义之路
  • Leetcode力扣解题记录--第240题(矩阵搜索)
  • 大规模金融数据相关性并行计算系统设计与实现