Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

模糊匹配高亮 #93

Open
Twlig opened this issue Apr 13, 2022 · 0 comments
Open

模糊匹配高亮 #93

Twlig opened this issue Apr 13, 2022 · 0 comments

Comments

@Twlig
Copy link
Owner

Twlig commented Apr 13, 2022

假设用户搜索上海,针对匹配信息项中上海字体高亮:

var arr = ['上海市公园', '上海自来水公司', '夜上海']
var value = '上海'
var ul = document.getElementsByTagName('ul')[0]
arr.forEach(item => {
    if(item.indexOf(value) !== -1) {
        let li = document.createElement('li')
        li.innerHTML = item.replace(value, `<span style="color: blue">${value}</span>`)
        ul.appendChild(li)
    }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant