gpt4 book ai didi

html - Bootstrap Accordion 在尝试使用动态 ID 时不起作用

转载 作者:行者123 更新时间:2023-12-04 15:40:49 25 4
gpt4 key购买 nike

它不会与 foreach 分配的 ID 一起折叠。

我已经用非动态 ID 尝试过它并且它有效。

<div class="accordion" id="myAccordion">
@foreach (var item in Model)
{
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#@item.Id">
@item.Version.Component.Product.Name's @item.Version.Component.Name's @item.Version.ReleaseNumber Version
</button>
</h5>
</div>
<div id="@item.Id" class="collapse" data-parent="#myAccordion">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
}
</div>
</div>

最佳答案

数字 id 不适用于 Bootstrap Accordion (参见 this question )。所以在 id 和 data 目标前加上一个字母。此外,当 @ 符号嵌入到字符串中时,您必须使用括号来标识要执行的代码。

        <div class="card-header">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#X@(item.Id)">
@item.Version.Component.Product.Name's @item.Version.Component.Name's @item.Version.ReleaseNumber Version
</button>
</h5>
</div>
<div id="X@(item.Id)" class="collapse" data-parent="#myAccordion">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>

正如@terrencep 提到的,您应该在浏览器的页面检查器中查看数据切换的值。

关于html - Bootstrap Accordion 在尝试使用动态 ID 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57868980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com