整理一些常用js

来源:互联网 发布:网络远程教育大学 编辑:程序博客网 时间:2024/06/05 08:41

1、js中将后台传来的timestamp转为指定格式

//日期转换方法Date.prototype.format = function(format) {      /*      * eg:format="yyyy-MM-dd hh:mm:ss";      * (new Date(app.ctime)).format("yyyy-MM-dd hh:mm:ss")     */      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;  } 
2、通用的序列化form

/* 工具方法 *///序列化表单function serializeForm(form) {var obj = {};$.each(form.serializeArray(), function(index) {if (obj[this['name']]) {obj[this['name']] = obj[this['name']] + ',' + $.trim(this['value']);} else {obj[this['name']] = $.trim(this['value']);}});return obj;}

3、公用的jsp

<%@include file="../taglibs.jsp"%>

4、包含头尾

<%@include file="../layout/head.jsp" %>


0 0