Replace all instances in string with a variable as the search - JavaScript

后端 未结 1 1303
既然无缘
既然无缘 2021-01-19 15:00

I am having an issue which I cannot find documented anywhere, i see a regex method however that is using a direct string rather than string within a variable. This is my cod

相关标签:
1条回答
  • 2021-01-19 15:49

    You are searching for the pattern that is literally "src." You need to use the RegExp class if you want to use variables in patterns:

    pattern = new RegExp(src, 'g');
    $(".entry-content")...html().replace(pattern, replacement);
    
    0 讨论(0)
提交回复
热议问题