0

我有以下代码:

var modal = $.modal({
                        title: title,
                        closeButton: true,
                        content: content,
                        width: 1000,
                        maxHeight: 850,
                        resizeOnLoad: true,
                        buttons: {
                            'Submit': function (win) {
                                submitHandler($link, $('#main-form'));
                            },
                            'Submit & Close': function (win) {
                                var rc = submitHandler($link, $('#main-form'));
                                if (rc == true) { win.closeModal(); }
                            },
                            'Close': function (win) {
                                win.closeModal();
                            }
                        }
                    });

我想要做的是根据正在创建的模式窗口的类型有一组不同的按钮。我尝试使用以下代码执行此操作,但出现错误:

                    if (title.substr(0, 4) == "Crea") {
                        title += $('#RowKey').val();
                        var btns = btns1;
                    }
                    if (title.substr(0, 4) == "Edit") {
                        var btns = btns1;
                    }
                    if (title.substr(0, 4) == "Dele") {
                        var btns = btns2;
                    }
                    var btns1 = new {
                        'Submit': function (win) {
                            submitHandler($link, $('#main-form'));
                        },
                        'Submit & Close': function (win) {
                            var rc = submitHandler($link, $('#main-form'));
                            if (rc == true) { win.closeModal(); }
                        },
                        'Close': function (win) {
                            win.closeModal();
                        }
                    }
                    var btns2 = new {
                        'Submit & Close': function (win) {
                            var rc = submitHandler($link, $('#main-form'));
                            if (rc == true) { win.closeModal(); }
                        },
                        'Close': function (win) {
                            win.closeModal();
                        }
                    }
                    var modal = $.modal({
                        title: title,
                        closeButton: true,
                        content: content,
                        width: 1000,
                        maxHeight: 850,
                        resizeOnLoad: true,
                        buttons: btns
                    });

我得到的错误在线:

var btns1 = new {

错误信息是:

Object doesn't support this action

我想我做作业的方式有问题,但我不知道该怎么做。我希望有人可以帮助我。

有人可以告诉我我做错了什么来帮助我。

4

2 回答 2

5

省略newfor 对象。

var btns1 = new { .. };

应该

var btns1 = {someProperty: someValue, ... };

新的替代方式:

var bts1 = new Object();
btns1.someProperty = someValue; ...
于 2012-05-31T14:04:03.720 回答
1

不需要new运算符:您可以通过 Object 字面量实例化您的新 Object:

var btns1 = { ... };
于 2012-05-31T14:03:56.860 回答