如何使用 Javascript 将 EJS 标签替换为另一个 EJS 标签

时间:2021-05-21 11:41:27

标签: javascript html svg ejs

所以我有一个包含此代码的 EJS 文件

<div class="map-container">
  <%- include ('./maps/world.ejs') -%>
</div>

这是一个保存为 .ejs 文件的 SVG 文件,因此我可以导入它并对其进行 css 操作。例如 path:hover 和其他东西。

问题

我想当人们点击例如 USA 时,地图将更改为美国地图 (usa.ejs)。

World map example

所以我尝试了类似的方法,但有些东西不起作用。

$(document).ready(() => {
    loadWorldMap_Event();
});

function loadWorldMap_Event() {
    const paths = $('path');
    for (let path of paths) {
        path.addEventListener('click', function (event) {
            const name = event.target.getAttribute('name') || event.target.getAttribute('data-name') || event.target.getAttribute('class')
            if (name.toLowerCase() == "united states") {
                const map_container = $('.map-container');
                map_container.innerHTML = "<%- include ('./maps/usa.ejs') -%>"
            }
        })
    }
}

请帮帮我!

0 个答案:

没有答案