试图动态插入模板片段

发布于 2025-01-22 05:51:10 字数 988 浏览 3 评论 0原文

我正在尝试使用从数据库中提取的URL通过后端插入图像,并尝试根据用户单击“更多按钮”时想要查看的费用来动态显示它们。 因此我正在努力理解使用此

show

showMoreBtn.innerText = 'Show More'
                showMoreBtn.addEventListener('click', () => {
                // const img = document.createElement('img')
                // img.src = `uploads/${exp.expFile}`
                // img.src = 'uploads/user2-165015.jpeg'
                console.log('exp File Path', exp.expFile)
                })

的语法和过程。

</template>
    <template id="expList">
        <section class="expSection">
            <h1 id="expID"></h1>
            <h2 id="expLabel"></h2>
            <p><button class="showMoreBtn" ></button></p>
            <!-- <img id="expImage" src="uploads/user2-1650152674035.jpeg" width="400" height="300"> -->
            </section>
    </template>

我是新手的备件, 从数据库作为模板棘手的数据库。任何帮助都将受到赞赏。谢谢

I am trying to insert an image through the backend using a URL pulled from a database and attempting to dynamically display them based on an expense that a user wants to see when they click the how more button. I am new to remplates so i'm struggling to understand the syntax and process of using this

Show More Button displayed in the template of HTML page

showMoreBtn.innerText = 'Show More'
                showMoreBtn.addEventListener('click', () => {
                // const img = document.createElement('img')
                // img.src = `uploads/${exp.expFile}`
                // img.src = 'uploads/user2-165015.jpeg'
                console.log('exp File Path', exp.expFile)
                })

Template code used in the HTML file

</template>
    <template id="expList">
        <section class="expSection">
            <h1 id="expID"></h1>
            <h2 id="expLabel"></h2>
            <p><button class="showMoreBtn" ></button></p>
            <!-- <img id="expImage" src="uploads/user2-1650152674035.jpeg" width="400" height="300"> -->
            </section>
    </template>

The question would be how would i dynamically insert these images from paths taken from a database as its tricky with templates. any help is appreciated. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你不解释 2025-01-29 05:51:10

首先,您需要获取部分元素:

const section = document.querySelector(".expSection");

然后将其添加到您的页面中:

section.appendChild(img);

First you need to get your section element:

const section = document.querySelector(".expSection");

And then to add it to your page you need to:

section.appendChild(img);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文