美文网首页
检索结果关键字标红

检索结果关键字标红

作者: sunowter | 来源:发表于2021-05-24 16:02 被阅读0次

html:

<span v-html="searchKeys(classInfo.code, keyWords)"> </span>

js

export function searchKeys(val, keywords) {

  let list = keywords && keywords.split(' ') || {}

  val = val + ''

  if (list.length) {

    list.map(keyword => {

      let words=val.match(new RegExp(keyword, 'ig'))

      if (words&&words[0]&&val.indexOf(words[0]) !== -1) {

        val = val.replace(words, '<font color="red">' + words + '</font>')

      } else {

          return val

      }

    })

  }

  return val

}

相关文章

网友评论

      本文标题:检索结果关键字标红

      本文链接:https://www.haomeiwen.com/subject/jhbxsltx.html