gpt4 book ai didi

javascript - 在 Angular 2 中查找和替换

转载 作者:行者123 更新时间:2023-12-03 04:13:08 25 4
gpt4 key购买 nike

我在字符串 tempType.tempcode 中有一个数据,如下所示。在很多地方都有这样的 URL 指向:

href=\"./assets/sources/template/....."

我的要求是我想编写一个函数,将所有 ./assets/sources/template 替换为 sources/template

    tempType.tempcode = < !DOCTYPE html > < html lang = "en" > < head > < meta charset = "utf-8" > < meta http - equiv = "X-UA-Compatible"
content = "IE=edge" > < meta name = "viewport"
content = "width=device-width, initial-scale=1" > < meta name = "description"
content = "" > < meta name = "author"
content = "" > {
{
META
}
} < link rel = "stylesheet"
href = "./assets/sources/template/css/bootstrap.min.css"
type = "text/css" > < link href = "https://fonts.googleapis.com/css?family=Poppins"
rel = "stylesheet" > < link href = 'http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800'
rel = 'stylesheet'
type = 'text/css' > < link href = 'http://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic'
rel = 'stylesheet'
type = 'text/css' > < link rel = "stylesheet"
href = "./assets/sources/template/font-awesome/css/font-awesome.min.css"
type = "text/css" > < link rel = "stylesheet"
href = "./assets/sources/template/css/animate.min.css"
type = "text/css" > < link rel = "stylesheet"
href = "./assets/sources/template/css/light-slider.css"
type = "text/css" > < link rel = "stylesheet"
href = "./assets/sources/template/css/style.css"
type = "text/css" > < link rel = "stylesheet"
href = "./assets/sources/template/css/common.css"
type = "text/css" > < /head> <body id="page-top"> <div id="main-wrapper"> {{CONTENT}} </div > <!-- jQuery --> <script src="./assets/sources/template/js/jquery.js"></script> <!-- Bootstrap Core JavaScript --> <script src="./assets/sources/template/js/bootstrap.min.js"></script> <!-- Plugin JavaScript --> <script src="./assets/sources/template/js/jquery.easing.min.js"></script> <script src="./assets/sources/template/js/jquery.fittext.js"></script> <script src="./assets/sources/template/js/wow.min.js"></script> <script src="./assets/sources/template/js/popupimage.js"></script> <!-- Custom Theme JavaScript --> <script src="./assets/sources/template/js/creative.js"></script> <script src="./assets/sources/template/js/light-slider.js"></script> <script src="./assets/sources/template/js/count.js"></script> <script src="./assets/sources/template/js/menu.js"></script> <script src="./assets/sources/template/js/vertical_list.js"></script> <script src="./assets/sources/template/js/sticky.js"></script> <script src="http://www.jqueryscript.net/demo/jQuery-Plugin-For-One-Page-Navigation-Plugin-Page-Scroll-To-ID/jquery.malihu.PageScroll2id.js"></script> <script> (function($){ $(window).load(function(){ $(".nav a").mPageScroll2id(); $("#lightSlider").lightSlider(); callCounter(); callvertical_list(); $(".menu2").sticky({ topSpacing: 0 }); }); })(jQuery); </script> </body> </html>

最佳答案

对于每个变量,您必须使用正则表达式,如下所示:

let pattern = '(./assets/sources/template)';
let regex = new RegExp(pattern, 'g');
let newString = yourVariable.replace(regex, 'sources/template');

关于javascript - 在 Angular 2 中查找和替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44243733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com