试图动态插入模板片段
我正在尝试使用从数据库中提取的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要获取
部分
元素:然后将其添加到您的页面中:
First you need to get your
section
element:And then to add it to your page you need to: