我有一个 html 文件和 JS 文件
所以我的 html 文件中有 svg 的语法:
<body>
<svg width="500" height="100">
<circle id="circle1" cx="20" cy="20" r="10"
style="stroke: none; fill: #ff0000;"/>
<text x="47.872" y="11.064">{home/sensors/temp/kitchen} °C</text>
<circle id="circle1" cx="20" cy="20" r="10"
style="stroke: none; fill: #ff0000;"/>
<title x="47.872" y="11.064" >{home/sensors/temp/bathroom} °C</title>
<circle id="circle1" cx="20" cy="20" r="10"
style="stroke: none; fill: #ff0000;"/>
<text x="47.872" y="11.064">{home/sensors/temp/room} °C</text>
</svg>
<script type="text/javascript" src="../scripts/link.js"></script>
</body>
</html>
目前,我的 link.js 中只有这个:
let listTickets = new Map([
['0', '{home/sensors/temp/kitchen}'],
['1', '{home/sensors/temp/bathroom}'],
['2', '{home/sensors/temp/room}']
]);
let listNumber = new Map([
['0', '24'],
['1', '22'],
['2', '25']
]);
// var topicMatch = line.match(/\{[\w\/]+\}/g); // think need to use regex
所以我想要在 js 文件中得到什么,就是我们在 html 文件中得到如下语法:
"{ + content + }
需要用他的值替换(在我的导航器中而不是在文件中)相同的语法,例如,我们正在读取 html 文件:
detect first content : {home/sensors/temp/kitchen} => need to change by '24'
detect second content : {home/sensors/temp/bathroom} => need to change by '22'
detect first content : {home/sensors/temp/kitchen} => need to change by '25'
感谢您的帮助