【发布时间】:2021-10-26 05:24:09
【问题描述】:
您好,我的登录页面上有引导模式
我有许多具有不同数据目标和模式的引导按钮。 modal 中的内容必须基于通过 modals ID 连接到 modal 的按钮数据目标显示 如何在不重复代码的情况下解决这个问题?
<button type="button" class="btn btn-dark" data-toggle="modal" data-target="#exampleModalLabel">Read more</button>
<div class="modal fade" id="exampleaModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Example</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<img src="" alt="" class="img-fluid mb-5" />
<p>Lorem Ipsum</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-
dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
【问题讨论】:
-
如何在不重复代码的情况下解决这个问题 这是什么意思?因为你必须复制代码并更改
id和data-target -
这样我必须复制 button 和 modal 并放置不同的 id 和 data-target
-
你的意思是一个模态和同一个模态的多个按钮?
-
我的意思是一种模式,根据按下的按钮显示不同的内容
-
我有一张引导卡,每张卡都有一个按钮,即模态按钮。所以按下按钮后,我需要显示正确的内容。
标签: javascript html jquery bootstrap-4