【发布时间】:2019-05-01 14:29:42
【问题描述】:
我有七个课程标题,它们显示在各自的 div 中,单击任何 div 都会打开一个模式。模式被硬编码到我的 HTML 中。
如何将每个课程标题附加到单击的模式中?例如,通过单击 Animals div 会弹出模式,并且标题“Animals”也应该出现。到目前为止,我只能显示第一个标题 (Animals) 并显示每个模态 (Animals,Capitals,Colors,etc) 中的每个标题。
JS sn-p:
loadCategories(){
let categs = _categories;
// using templates to clone a single div based on how many Categories are present
let $host = $("#host");
for (var i = 0; i < categs.length; i++) {
let $template = $("#template").clone();
$template.find(".cat-box > .cat-title").text(categs[i].Title);
// $(".modal-title").append(categs[i].Title) // ------- shows everything (must be due to the loop)
$host.append($template.html());
}
// wondering if categs[i].Title could be worked with somehow
$(".modal-title").append(categs.Title)
let container = document.querySelector("div#template");
container.innerHTML = $host;
}
模态:
<div class="modal" id="modal-id" role="dialog">
<div class="modal-title" id="exampleModalLabel"></div>
【问题讨论】:
标签: javascript jquery html object bootstrap-modal