是否可以将 JConfirm 插件与 if 语句一起使用以在弹出窗口中显示不同的按钮,还是只需要硬编码?
我在脑海中计划了以下内容:
如果帐户激活
-> 是的,显示一个停用按钮
-> 不,显示一个激活按钮
这将编写如下代码:
$.confirm({
icon: 'fas fa-users',
title: 'User Account: $name',
content: 'What would you like to do with this account?',
buttons: {
View: {
btnClass: 'btn-info',
text: 'View Profile',
action: function () {
// Take them to a link
}
},
Upgrade: {
btnClass: 'btn-info',
text: 'Upgrade to Tutor',
action: function () {
$.alert('Account successfully upgraded!');
}
},
Ban: {
btnClass: 'btn-danger',
text: 'Ban Account',
action: function () {
$.alert('Account has now been banned :(');
}
},
if(activated === '1'){
Deactivate: {
btnClass: 'btn-warning',
text: 'Deactivate Account',
action: function () {
$.alert('Account has now deactivted :(');
}
}
} else {
Deactivate: {
btnClass: 'btn-warning',
text: 'Activate Account',
action: function () {
$.alert('Account has now deactivted :(');
}
}
}
Reset: {
btnClass: 'btn-success',
text: 'Reset Password',
action: function () {
$.alert('User has been e-mailed a forgotten password link');
}
},
Close: {
btnClass: 'btn-default',
text: 'Close'
}
}
});
此代码目前不起作用,有什么可能的方法来解决这个问题?