[英]Javascript find replace content that has "/" in the search string
I have javascript code which finds and replaces all instances of a value on a page.我有 javascript 代码,用于查找并替换页面上的所有值实例。 I am working with a CMS so unfortunately I need to work around lack of flexibility with the base HTML.
我正在使用 CMS,因此不幸的是,我需要解决基本 HTML 缺乏灵活性的问题。
document.body.innerHTML = document.body.innerHTML.replace(/VALUE/g, new_value);
I want to find a replace a url link using the same process.我想使用相同的过程找到一个替换 url 链接。 How do I take into account for the"/" in the search and replace strings?
如何在搜索和替换字符串中考虑“/”?
Example:例子:
find_str = "www.mysite.com/folder";
replace_str = "app.mysite.com/page";
document.body.innerHTML = document.body.innerHTML.replace(/find_str/g, replace_str);
Thank you both for your replies.谢谢你们的回复。 I have taken advice from both and changed my code as follows:
我已经听取了两者的建议,并将我的代码更改如下:
jQuery('a[href="tttps://www.mysite.com/folder"]').attr("href", "tttps://app.mysite.com/page");
PS: I cannot add https://
to the above as it will not let me save, so I added tttps://
instead. PS:我不能在上面添加
https://
,因为它不会让我保存,所以我添加了tttps://
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.