Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the steps for Jquery to operate js arrays and objects

php中世界最好的语言
Release: 2018-04-24 14:38:11
Original
1505 people have browsed it

This time I will bring you a detailed explanation of the steps for Jquery to operate jsarraysandobjects. What are the precautions for Jquery to operate js arrays and objects? The following are Let’s take a look at practical cases.

Post a piece of jQuery's operation on js objects and arrays: add, delete, modify and check the code.

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 
Delete
Work(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
=&#39;DeleteWork(\"" + val.Id + "\")&#39;>×</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(); 
        } 
    } 
}
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

jQuery plug-in implements table color change on alternate rows and interacts with mouse events

jquery moves from array Detailed explanation of steps to remove selected values

The above is the detailed content of Detailed explanation of the steps for Jquery to operate js arrays and objects. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template