我需要将userName传递到引导模式窗口,并在模式窗口中显示传递的名称。
例如,
如果我通过颚骨,模态将显示类似“这是颚骨”的内容
答案 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>
谢谢