[英]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.