Как передать значение в модальное окно
Столкнулся с такой проблемой, необходимо в модальное окно передать значение из кнопки. Я видел другие ответы на такой вопрос, но я не использую angular, только jquery, и ради одной страницы не хочеться его подключать.
Код
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Заголовок :lebedev:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<a :href="invite" target="popup" onclick="window.open('1 или 2 или 3','name','width=450,height=650')"><button class="bestButtons">Добавить</button></a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
<button type="button" data-toggle="modal" data-target="#exampleModalCenter" class="btn btn-primary" style="margin-top: 30px; padding-left: 15px">1</button>
<button type="button" data-toggle="modal" data-target="#exampleModalCenter" class="btn btn-primary" style="margin-top: 30px; padding-left: 15px">2</button>
<button type="button" data-toggle="modal" data-target="#exampleModalCenter" class="btn btn-primary" style="margin-top: 30px; padding-left: 15px">3</button>
Ответы (1 шт):
Автор решения: Yaroslav Molchan
→ Ссылка
В вопросе не указали что именно будете передавать и куда получать, какая версию бутстрапа, так что ответ уже под себя подстроите:
$('#exampleModalCenter').on('show.bs.modal', function(e) {
// Берём название кнопки, по которой вызывали модалку
const btnName = $(e.relatedTarget).text();
// И вставляем его в саму модалку
$(e.currentTarget).find('.modal-title').val(btnName);
});
Работать должно на версиях 3.2.0+