0

我在 jquery 中有一个变量。首先是添加一些值。现在再次向现有变量添加更多值。这是我的代码。如果有人知道帮助我......

var eventToAdd = {
                        title: $("#txtSubject").val(),
                        description: $("#addEventDesc").val(),
                        start: $("#txtStartdate").val(),
                        end: $("#txtEnddate").val()
                    };
                    var ChkBox = document.getElementById("rbtnHourly");
                    if (ChkBox.checked == true) {
                         **eventToAdd = {**
                            FREQ: "Hourly",
                            INTERVAL: $("#updown").val(),
                            BYSETPOS: "",
                            BYDAY: "",
                            BYMONTH: "",
                            BYMONTHDAY: ""
                        };
                    }
                    var ChkBox = document.getElementById("rbtnDaily");
                    if (ChkBox.checked == true) {
                        var rbtnEveryday = document.getElementById("rbtnEveryday");
                        if (rbtnEveryday.checked == true) {
                            **eventToAdd  = {**
                                FREQ: "Daily",
                                INTERVAL: $("#TextBox1").val(),
                                BYSETPOS: "",
                                BYDAY: "MO,TU,WE,TH,FR,SA,SU",
                                BYMONTH: "",
                                BYMONTHDAY: ""
                            };
                        }
                        else {
                           **var eventToAdd1 = {**
                                FREQ: "Daily",
                                INTERVAL: 1,
                                BYSETPOS: "",
                                BYDAY: "MO,TU,WE,TH,FR",
                                BYMONTH: "",
                                BYMONTHDAY: ""
                            };
                        };
                    }
4

2 回答 2

0

我不完全确定你在问什么,但看看jQuery.extend()

http://api.jquery.com/jQuery.extend/

这使您可以使用其他值扩展对象

于 2013-01-19T09:28:52.107 回答
0

您可以通过将属性分配给现有对象来向现有对象添加值,如下所示:

if (ChkBox.checked) {
    eventToAdd.FREQ = "Hourly";
    eventToAdd.INTERVAL = $("#updown").val();
    eventToAdd.BYSETPOS = "";
    eventToAdd.BYDAY = "";
    eventToAdd.BYMONTH = "";
    eventToAdd.BYMONTHDAY = "";
}
于 2013-01-19T09:44:08.787 回答