forked from lijinke666/javascript-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path模板.html
36 lines (31 loc) · 837 Bytes
/
模板.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Js实现模板</title>
<style>
body{
font-size: 30px;
}
</style>
</head>
<body>
<!--<p>你好{str}</p>-->
<div>hello! { str11 }</div>
</body>
<script>
window.onload=function(){
function temp(str,change){
var newStr = str.replace(/\{\s*(\w+)\s*\}/g,change);// \s匹配空格 *0个或多个 \w匹配单词 +至少一个或多个 g全局匹配
return console.log(newStr);
}
var str = "hello{ str }";
temp(str,"李金珂");
function temp2(change){
var newStr = document.body.innerHTML.replace(/\{\s*(\w+)\s*\}/g,change);
document.body.innerHTML=newStr;
}
temp2('世界');
}
</script>
</html>