繁体   English   中英

如何用其他东西替换部分字符串?

[英]how to replace part of string with something else?

var string='url("images/bgtr.svg") top right no-repeat, url("images/bgbl.svg") bottom left no-repeat, url("images/overlay.png"), linear-gradient(45deg, #5f796b, #3a4e59, #2f394e);'

如何用不同的字符替换linear-gradient(45deg, #5f796b, #3a4e59, #2f394e) 它可能并不总是“线性渐变”

使用String.prototype.replace() - JavaScript | MDN

replace()方法返回一个新字符串,其中部分或所有模式匹配项被替换项替换。 模式可以是字符串或正则表达式,替换可以是字符串或每次匹配时调用的函数。

我假设test是下面代码片段中的不同字符串

 var string='url("images/bgtr.svg") top right no-repeat, url("images/bgbl.svg") bottom left no-repeat, url("images/overlay.png"), linear-gradient(45deg, #5f796b, #3a4e59, #2f394e);' var replacedString = string.replace('linear-gradient(45deg, #5f796b, #3a4e59, #2f394e)', 'test'); console.log(replacedString);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM