1 $().ready(function () { 2 GetNowTime(); 3 4 5 6 }) 7 8 //获取当前时间 9 function GetNowTime() { 10 $("#NowTime").text(getQueryString("time")); 11 } 12 //填写(修改)报备的时间,得出报备属于“过去”还是“未来” 13 function GetTimeIn() { 14 var date = new Date(); 15 return (ToDate(getQueryString("time")) > ToDates(date.toLocaleDateString()));//返回true则插入未来表 16 17 } 18 //转换时间类型,根据-分割 19 function ToDate(str) { 20 var sd = str.split("-"); 21 return new Date(sd[0], sd[1], sd[2]); 22 } 23 //转换时间类型,根据/分割 24 function ToDates(str) { 25 var sd = str.split("/"); 26 return new Date(sd[0], sd[1], sd[2]); 27 } 28 //获取URL参数time 29 function getQueryString(name) { 30 var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); 31 var r = window.location.search.substr(1).match(reg); 32 if (r != null) { 33 return unescape(r[2]); 34 } 35 return null; 36 } 37 //日期差方法(暂未使用) 38 Date.prototype.diff = function (date) { 39 return (this.getTime() - date.getTime()) / (24 * 60 * 60 * 1000); 40 // 调用日期差方法,求得参数日期与系统时间相差的天数 41 var date = new Date(getQueryString("time")); 42 var diff = now.diff(date);// 打印日期差 43 alert(diff > 10); 44 } 45 //减10天得到不能 46 function addDate(date, days) { 47 var d = new Date(date); 48 d.setDate(d.getDate() + days); 49 var m = d.getMonth() + 1; 50 return d.getFullYear() + '-' + m + '-' + d.getDate(); 51 } 52 function cancel() { 53 54 document.getElementById("Cancel").style.backgroundColor = "#047dd1"; 55 } 56 //保存按钮事件 57 function save() { 58 59 document.getElementById("Save").style.backgroundColor = "#047dd1"; 60 Assignment(); 61 62 } 63 //调用ajax方法传值 64 function CAjax(Menu, InTime, optime, edtime, WorkAss, JobContent) { 65 $.ajax({ 66 type: "post", 67 url: "Route.ashx?type=" + Menu + "&random=" + Math.random(), 68 datatype: "json", 69 data: { 70 "intime": InTime, 71 "opentime": optime, 72 "endtime": edtime, 73 "workAss": WorkAss, 74 "jobcontent": JobContent, 75 }, 76 success: function () { 77 alert("传值成功") 78 }, error: function () { 79 alert("传值失败") 80 } 81 }) 82 } 83 //保存(将需要保存的值传到后台) 84 function Assignment() { 85 var optime = $("#OpTime").val(), edtime = $("#EdTime").val(), WorkAss = $("#WorkAss").val(), JobContent = $("#JobContent").val(), InTime = getQueryString("time"); 86 if (optime == "" || edtime == "" || WorkAss == "" || JobContent == "" || InTime == "") { 87 alert("内容填写不完整!") 88 } else { 89 90 var now = new Date(); 91 var days = -9; 92 var edays = addDate(now.toLocaleDateString(), days); 93 var d1 = ToDate(edays); 94 var d2 = ToDate(getQueryString("time")); 95 // alert(d2 >= d1);//本地时间十天前的不能做任何操作,当表达式==true时,可以进行操作 96 if (d2 >= d1) { 97 if (GetTimeIn()) { 98 var Menu = "add"; 99 CAjax(Menu, InTime, optime, edtime, WorkAss, JobContent); 100 101 } else { 102 var Menu = "update"; 103 CAjax(Menu, InTime, optime, edtime, WorkAss, JobContent); 104 } 105 } else { 106 alert("已过填写日期!") 107 } 108 109 } 110 111 }
根据时间判断,然后任务报备属于过去还是未来,执行不同的操作