简体   繁体   English

在 jquery.confirm.js 中使用数据属性

[英]Using data attributes with jquery.confirm.js

I'm trying to utilise the jquery.confirm script.我正在尝试使用jquery.confirm脚本。 It's all firing as expected but I'm trying to use custom data attributes that are passed into a controller elsewhere on the site, but I'm getting the error of undefined .这一切都按预期进行,但我正在尝试使用传递到站点其他地方的控制器的自定义data属性,但我收到了undefined的错误。

<a class="confirmMemberDelete" data-title="Mr Goose" data-user="CON-000132456" data-username="Mr Goose" href="#">
$(".confirmMemberDelete").confirm({
    text: "Are you sure that you wish to delete this user?",
    confirm: function (button) {
        var conNum = $(this).attr('data-user');
        var conName = $(this).attr('data-username');
        alert("You just confirmed.");
        alert($(this).attr('data-user'));
    },
    cancel: function (button) {
        alert("You aborted the operation.");
    },
    confirmButton: "Yes I am",
    cancelButton: "No"
});

The two custom data attributes are data-user and data-username .两个自定义data属性是data-userdata-username data-title is used by the confirm script as a title for the confirmation box.确认脚本使用data-title作为确认框的标题。

I can't find any documentation online so any help would be marvellous.我在网上找不到任何文档,所以任何帮助都会很棒。

Still not fixed in version 3.3.4, but I'm able to extract the data attributes the following way.在 3.3.4 版本中仍未修复,但我可以通过以下方式提取数据属性。

<a class="confirmMemberDelete" data-title="Mr Goose" data-user="CON-000132456" data-username="Mr Goose" href="#">

$('.confirmMemberDelete').confirm({
    title: 'Make this my profile picture',
    buttons: {
        ok: function () {
            let user = $(this)[0].$target[0].dataset.user;              
            let username = $(this)[0].$target[0].dataset.username;              
            console.log(user, username);

        },
        cancel: function () {

        }
    }
});

Check out this fiddle看看这个小提琴

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

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