欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Jquery操作js数组及对象示例代码

程序员文章站 2023-02-18 13:49:49
贴一段jquery对js对象及数组的操作:增删改查的代码。 . 代码如下: var worklist = new array();//数组对象 //下面是自己定义的实体...

贴一段jquery对js对象及数组的操作:增删改查的代码。

. 代码如下:


var worklist = new array();//数组对象
//下面是自己定义的实体
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
            + ",任职时间:" + getjsdate(val.begintime) + "到" + getjsdate(val.endtime) + "<a href=\"#\" onclick='deletework(\"" + val.id + "\")'>×</a></span>";
    });
    $("#tdworklist").html(html);
}
function addwork() {
    if(checkisnull("workaddress","工作地址不能为空")
        && checkisnull("worklevel", "职责不能为空")
        && checkisnull("workbegin", "工作开始日期不能为空")
        && checkisnull("workleave", "工作结束日期不能为空")
        )
    {
        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("存在相同的工作经历。"); isok= false;
            } 
        });
        if (isok){
                var onework = new workex($("#workaddress").val(), $("#worklevel").val(),
                        $("#workbegin").val(), $("#workleave").val())
                worklist.push(onework);
                //  <span class="add_work_unit">四川省乐天区某某制药厂<a href="#">×</a></span>
                showwork();
        }
    }
}