简体   繁体   English

如何在 Bootstrap 4 popover 事件中获取数据属性

[英]How to get data attributes in Bootstrap 4 popover event

I have this situation.我有这种情况。

open popover button:打开弹出按钮:

<a href="#" id="popover" data-plan-type="2" data-toggle="popover" data-html="true" data-placement="bottom">
<i class="fal fa-plus-circle"></i></a>

popover settings:弹窗设置:

let orderPlanPopoverSettings = {

        html: true,
        selector: 'a#order-plan-popover',
        content: function () {

            return $('#popover_content_wrapper').html();

        }

    };

popover:弹出框:

$('body').popover(orderPlanPopoverSettings).on('show.bs.popover', function(e) {

   //GET POPOVER BUTTON data-plan-type

});

I need get in show.bs.popover button data attributes data-plan-type我需要进入show.bs.popover按钮数据属性数据计划类型

The event target ( e.target ), is the element that triggered the popover.事件目标( e.target )是触发弹出框的元素。 Then use jQuery data() for the "plan-type" value..然后使用 jQuery data()作为“计划类型”值..

$('body').popover(orderPlanPopoverSettings).on('show.bs.popover', function(e) {

   //GET POPOVER BUTTON data-plan-type
   var planType = $(e.target).data("plan-type");
   console.log(planType);

});

Demo: https://www.codeply.com/go/I7Zh7ohhJw演示: https : //www.codeply.com/go/I7Zh7ohhJw

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

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