Jquery操作js数组及对象示例代码_jquery
程序员文章站
2022-04-10 19:20:54
...
贴一段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 + " " + val.DepartmentName + ":" + val.Title
+ ",任职时间:" + GetJsDate(val.BeginTime) + "到" + GetJsDate(val.EndTime) + "×";
});
$("#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);
// 四川省乐天区某某制药厂×
ShowWork();
}
}
}
复制代码 代码如下:
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 + " " + val.DepartmentName + ":" + val.Title
+ ",任职时间:" + GetJsDate(val.BeginTime) + "到" + GetJsDate(val.EndTime) + "×";
});
$("#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);
// 四川省乐天区某某制药厂×
ShowWork();
}
}
}
推荐阅读
-
Jquery动态添加及删除页面节点元素示例代码_jquery
-
JQUERY 获取IFrame中对象及获取其父窗口中对象示例_jquery
-
JS和JQUERY获取页面大小,滚动条位置,元素位置(示例代码)_jquery
-
原生JS forEach()和map()遍历的区别、兼容写法及jQuery $.each、$.map遍历操作
-
JS/jQuery实现获取时间的方法及常用类完整示例
-
jQuery LigerUI 插件介绍及使用之ligerDrag和ligerResizable示例代码打包_jquery
-
JS数组中对象去重操作示例
-
JS实现根据数组对象的某一属性排序操作示例
-
JS实现数组去重及数组内对象去重功能示例
-
jQuery操作cookie的示例代码