1. [代码] [JavaScript]代码 //写入cookiefunction setCookie(name, value) { var Days = 30; //此 cookie 将被保存 30 天 var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + esc
1. [代码][JavaScript]代码
//写入cookie function setCookie(name, value) { var Days = 30; //此 cookie 将被保存 30 天 var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); } ///删除cookie function delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); } //读取cookie function getCookie(name) { var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (arr != null) return unescape(arr[2]); return null; } //===================== cookie相关 end ======================== // //===================== form 表单 序列化 插件 相关 beign ======================== // var $ = jQuery; (function($){ $.fn.serializeJson=function(){ var serializeObj={}; var array=this.serializeArray(); var str=this.serialize(); $(array).each(function(){ if(serializeObj[this.name]){ if($.isArray(serializeObj[this.name])){ serializeObj[this.name].push(this.value); }else{ serializeObj[this.name]=[serializeObj[this.name],this.value]; } }else{ serializeObj[this.name]=this.value; } }); return serializeObj; }; })(jQuery); //===================== form 表单 序列化 插件 相关 end ======================== // //===================== 回车触发 子页面 查询事件 相关 beign ======================== // // 主框架页上增加 回车触发frame子页 查询动作 (仅当子页面有 .btnSearch的按钮时才触发) jQuery(window.document).keyup(function (event) { if(event.which == '13') { var jBtn = jQuery(".btnSearch"); if (jBtn.length > 0) { jBtn.click(); } } });
2. [代码]给全局js中new Data()添加方法
//=====================日期格式化 相关 beign ======================== // Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, //month "d+": this.getDate(), //day "h+": this.getHours(), //hour "m+": this.getMinutes(), //minute "s+": this.getSeconds(), //second "q+": Math.floor((this.getMonth() + 3) / 3), //quarter "S": this.getMilliseconds() //millisecond } if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o)if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); return format; } Date.prototype.add = function (strInterval, Number) { var dtTmp = this; switch (strInterval) { case 's' : return new Date(Date.parse(dtTmp) + (1000 * Number)); case 'n' : return new Date(Date.parse(dtTmp) + (60000 * Number)); case 'h' : return new Date(Date.parse(dtTmp) + (3600000 * Number)); case 'd' : return new Date(Date.parse(dtTmp) + (86400000 * Number)); case 'w' : return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number)); case 'q' : return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number * 3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); case 'm' : return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); case 'y' : return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); } } //=====================日期格式化 相关 end ======================== //