如何使用条件的JConfirm?

时间:2018-03-08 13:35:19

标签: javascript php jquery jconfirm

是否可以使用带有if语句的JConfirm插件在弹出窗口中显示不同的按钮,还是只需要硬编码?

我曾在脑海里计划过以下内容:

  

如果帐户已激活

     

- >是的,显示停用按钮

     

- >不,显示激活按钮

会编写如下代码:

                $.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'
                        }   
                    }
                });

这段代码目前不起作用,这可能是什么方法呢?

0 个答案:

没有答案