在不发送 get 请求的情况下模拟 hx-swap 的安全方法?

问题描述 投票:0回答:1
innerhtml htmx hx-swap
1个回答
0
投票

尝试直接克隆节点。也许:

document.getElementById('content_div').replaceChildren(...document.getElementById('socials').cloneNode(true).childNodes);

如果您使用 HTML template 元素,则可以使用稍微更简洁的版本,该元素是为此类场景设计的:

document.getElementById('content_div').replaceChildren(document.getElementById('socials').content.cloneNode(true));
<template id='socials'>
    <div class="Social-media fade-in">
        <a href="https://stackoverflow.com/users/4231985/kkawabat" target="_blank"><i class="fab fa-stack-overflow"></i></a>
        <a href="https://github.com/kkawabat" target="_blank"><i class="fab fa-github"></i></a>
        <a href="https://www.linkedin.com/in/kan-kawabata-8b4106a2/" target="_blank"><i class="fab fa-linkedin"></i></a>
    </div>
</template>
© www.soinside.com 2019 - 2024. All rights reserved.