[英]Using data attributes with jquery.confirm.js
我正在尝试使用jquery.confirm脚本。 这一切都按预期进行,但我正在尝试使用传递到站点其他地方的控制器的自定义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"
});
两个自定义data
属性是data-user
和data-username
。 确认脚本使用data-title
作为确认框的标题。
我在网上找不到任何文档,所以任何帮助都会很棒。
在 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 () {
}
}
});
看看这个小提琴
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.