[英]javascript .replace a html tag does not replace
I am trying to replace some html but the replace is not taking place. 我正在尝试替换一些html,但是替换没有发生。 I am using the javascript
.replace
and from what I can see I am using it right. 我正在使用javascript
.replace
,从中可以看到我正在正确使用它。
content.replace('<link rel="stylesheet" href="style.css">', '<style>html{background-color: blue;}<\/style>');
The strings replace()
method returns a new string with the new value. 字符串
replace()
方法返回具有新值的新字符串。 It doesn't modify the original string. 它不会修改原始字符串。
Here is a simple example: 这是一个简单的示例:
var str = "Hello World!";
var res = str.replace("World", "Foo");
console.log(str); // prints Hello World!
应该这样做:
$('[href="style.css"]').prepend("html{background-color: blue;}");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.