按下按钮时,访问Div A按钮包裹
我目前正在设计一个将加载在可用项目列表中的网站。我正在使用EJS从数据库中动态加载项目并将其显示在单独的DIV中。但是,我希望用户能够从列表中选择其中一个项目。我已经在每个Divs上添加了一个按钮,但是我不确定如何制作它,以便按下按钮时,它访问了DIV的嵌套。
在下面
<%for(var i = 0; i<groups.length; i++){%>
<div class="col-md-4">
<div class="card rider-card">
<div class="card-body">
<h4 class="card-title">Text Here</h4>
<h5 class="card-subtitle mb-2 text-muted">Text Here</h5>
<h6 class="card-text">___ spots available</h6>
<p class="card-text">Text Here</p>
<a onclick="selectDriver()" class="stretched-link"></a>
</div>
</div>
</div>
<%}%>
代码 数据库中的数据,并将集合称为组。我迭代组并为每个组创建一张新卡。因为我正在动态生成Divs,所以我似乎找不到一种区分它们的方法。该按钮是锚标签,适用于整个卡。
有没有办法仅访问锚标签嵌套的卡?
I'm currently designing a website that loads in a list of available items. I'm using EJS to dynamically load the items in from a database and displaying them in separate divs. However, I want the user to be able to select one of the items from the list. I've added a button to each of the divs, but I'm not sure how to make it so that when a button is pressed, it accesses the div it is nested in.
The code is below
<%for(var i = 0; i<groups.length; i++){%>
<div class="col-md-4">
<div class="card rider-card">
<div class="card-body">
<h4 class="card-title">Text Here</h4>
<h5 class="card-subtitle mb-2 text-muted">Text Here</h5>
<h6 class="card-text">___ spots available</h6>
<p class="card-text">Text Here</p>
<a onclick="selectDriver()" class="stretched-link"></a>
</div>
</div>
</div>
<%}%>
I'm using MongoDB to store the data in the database, and calling the collection as groups. I iterate through the groups and create a new card for each one. Because I'm dynamically generating the divs, I can't seem to find a way to differentiate them. The button is the anchor tag, which applies to the entire card.
Is there a way to access only the card the anchor tag is nested in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用模板语言为每张卡创建一个逐渐增加的ID,使用您的“ for”循环中的i变量:
如果您想在其他地方引用该卡,这很有用。或者,您可以通过parenthnodes冒泡并钩住上方的div
You can use the template language to create a gradually incrementing id for each card, using the i variable in your 'for' loop:
That's useful if you want to refer to the card in other places also. Alternately, you could bubble up and hook into the div above via parentnodes