如何使用具有相同 ID 的多个按钮打开相同模式?

How to open same modal with multiple button which have same id?

我有一个 foreach 循环,我在其中创建了 x 个按钮:

 <a data-toggle="modal" data-target="#unlockModal" id="openUnlockModal" data-uid="@user.Uid" class="btn btn-default btn-sm">test</a>

如您所见,所有这些按钮的 ID 都相同,当然,如果我单击其中一个按钮,则只有这些按钮列表中的第一个按钮会打开模式。

 $("#openUnlockModal").on("click", function (event) {
        var uid = $(this).data("uid");
        console.log(uid)
     //open my fancyModal here
    });

我面临的问题是我想将一个 id 发送到存储在实际打开它的按钮上的模态。

那么我如何将这个 id 从按钮发送到模式?以及如何让所有按钮都起作用?

id页面必须只有一个,可以给class添加事件,像这样

$(".btn").on("click", function (event) {
    var uid = $(this).data("uid");
    // $(this) will be refer to button which was clicked 
    console.log(uid)
});