Javascript search issue

后端 未结 1 416
失恋的感觉
失恋的感觉 2021-01-26 08:01

I have a piece of code that searches through a table looking for a certain phrase. Once it finds the phrase, it returns the innerHTML of the current cell to a div near the top o

相关标签:
1条回答
  • 2021-01-26 08:46

    As you are just wanting to check for presence of a specific string, I think your solution will probably be more robust if you use indexOf rather than RegExps.

    Using RegExps, if you are looking for special characters eg [ or ] or ( or ) then you will need to escape them, this is just another layer of complexity which I don't think you need to introduce.

    So try replacing regex usages such as...

    if (currentRow.innerHTML.match(map_regex))
    

    with this...

    if (currentRow.innerHTML.indexOf(mapString)!=-1)
    
    0 讨论(0)
提交回复
热议问题