Jquery operates on js arrays and object sample code


Post a section of jQuery on js objects and array operations: add, delete, change and look up the code.

var WorkList = new Array();//The array object
//Here are the self-defined entities
function WorkEx(depart, title, begintime, endtime) {
    this.SId = 0;
    this.Id = -(WorkList.length+1);
    this.DepartmentName = depart;
    this.Title = title;
    this.BeginTime = begintime;
    this.EndTime = endtime;
    this.Description = "";
    this.Enable = 0;
    return this;
}
function DeleteWork(guid) {
      WorkList = $.grep(WorkList, function (val, key) {
          return val.Id != guid;
    });
      ShowWork();
}
function ShowWork() {
    var html = "";
    $.each(WorkList, function (key, val) {
        html = html + " <span class="add_work_unit">" + val.DepartmentName + ":" + val.Title
            + ", Duration: " + GetJsDate(val.BeginTime) + " to " + GetJsDate(val.EndTime) + "<a href="#" onclick='DeleteWork("" + val.Id + "")'> x </a></span>";
    });
    $("#tdWorkList").html(html);
}
function AddWork() {
    if(CheckIsNull("workaddress"," The work address cannot be empty ")
        && CheckIsNull("worklevel", " Duty cannot be idle ")
        && CheckIsNull("WorkBegin", " The work start date cannot be empty ")
        && CheckIsNull("WorkLeave", " The work end date cannot be empty ")
        )
    {
        var isok = true;
        $.each(WorkList, function (key, val) {
            if (val.DepartmentName == $("#workaddress").val()
              && val.Title == $("#worklevel").val()
                && val.BeginTime == $("#WorkBegin").val()
                 && val.EndTime == $("#WorkLeave").val()
                )
            {
                alert(" The same work experience exists. "); isok= false;
            } 
        });
        if (isok){
                var onework = new WorkEx($("#workaddress").val(), $("#worklevel").val(),
                        $("#WorkBegin").val(), $("#WorkLeave").val())
                WorkList.push(onework);
                //  <Span class = "add_work_unit>" Pharmaceutical factory & lt, lotte district, sichuan province; A href = "#"> X </ a> </ span>
                ShowWork();
        }
    }
}