如何通过切换将特定ID传递给Bootstrap Modal
<%= link_to ' Reject', '#myModal', 'data-toggle' => 'modal',class: "btn btn-danger btn btn-primary btn-sm",:id =>applyleave.id %> </td
<div class="modal-body">
<%= text_field_tag :adminreason,:id =>applyleave.id %>
</div>
答案 0 :(得分:1)
我们需要在按钮中添加服装数据ID,如下所示,
<button type="button" data-toggle="modal" data-target="##myModal" data-id="jawa">Delete</button>
此JS函数将在打开boostrap模态窗口之前被调用。在该函数中,我们可以获取data-id属性值,然后可以基于获取值编写代码。参见下面的代码,
<script type="text/javascript">
$('#myModal').on('show.bs.modal', function(event) {
var userName = $(event.relatedTarget).data('id');
$("#modalText").html("You are going to be deleted" + userName);
});
</script>
这是模式窗口代码,
<div id="myModal" class="modal fade" role="dialog" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="cancelModal">Google Map</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="modalText"></div>
</div>
<div class="modal-footer">
<a href="" target="_blank" id="mapLink">Open in new tab</a>
</div>
</div>
</div>
</div>
希望,这会对您有所帮助。