Javascript查找替换搜索字符串

时间:2015-11-19 04:24:24

标签: javascript html

我有javascript代码,可以查找并替换页面上所有值的实例。我正在使用CMS,所以不幸的是我需要解决基本HTML缺乏灵活性的问题。

document.body.innerHTML = document.body.innerHTML.replace(/VALUE/g, new_value);

我想找到一个使用相同进程替换url链接。如何在搜索和替换字符串中考虑“/”?

示例:

find_str = "www.mysite.com/folder";
replace_str = "app.mysite.com/page";
document.body.innerHTML = document.body.innerHTML.replace(/find_str/g, replace_str);

1 个答案:

答案 0 :(得分:0)

感谢您的回复。我从两者中获得了建议并更改了我的代码如下:

jQuery('a[href="tttps://www.mysite.com/folder"]').attr("href", "tttps://app.mysite.com/page");

PS:我无法将https://添加到上面,因为它不会让我保存,所以我添加了tttps://