简体   繁体   English

将ID传递给Bootstrap Modal?

[英]Pass ID into Bootstrap Modal?

How do I pass ID from <button> into Bootstrap Modal. 如何将ID从<button>传递到Bootstrap Modal。 So I can use ID to get information from ajax to display in the Modal. 因此,我可以使用ID从ajax获取信息以在Modal中显示。

For example: 例如:

Button: 按键:

<button id="123" type="button" class="btn btn-sm" data-toggle="modal" data-target="#Testing">Edit</button>

Should I use shown.bs.modal do this? 我应该使用shown.bs.modal吗?

$("#Testing").on('shown.bs.modal', function () { 
  // How to get ID? id="??"
  //Ajax
});

You can use event object that is passed to the show.bs.modal handler. 您可以使用传递给show.bs.modal处理程序的event对象。

$('#Testing').on('show.bs.modal', function (event) {
    var id = $(event.relatedTarget).attr('id');
});

event.relatedTarget refers to the button that has triggered the modal open event. event.relatedTarget是指已触发模式打开事件的按钮。

Bootstrap Documentation 引导文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM