function $(id){
|
return document.getElementById(id);
|
}
|
|
function geib(id){
|
return document.getElementById(id);
|
}
|
|
function elesByName(name){
|
return document.getElementsByName(name);
|
}
|
|
function elesByTag(name){
|
return document.getElementsByTagName(name);
|
}
|
|
function createEle(name){
|
return document.createElement(name);
|
}
|
|
//封装trim函数
|
String.prototype.trim=function(){
|
return this.replace(/(^\s*)|(\s*$)/g,"");
|
};
|
|
//封装ajax
|
//参数:请求方式,请求url,发送的数据,回调函数
|
function $ajax(method,url,data,callback){
|
var xhr;
|
if(window.XMLHttpRequest){
|
xhr=new XMLHttpRequest();
|
}else{
|
xhr=new ActiveXObject('Micsoft.XMLHTTP');
|
}
|
xhr.open(method, url, true);
|
xhr.onreadystatechange=function(){
|
if(xhr.readyState==4 && xhr.status==200)
|
callback(xhr.responseText);
|
};
|
if(method.toLowerCase()=="post"){
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
}
|
xhr.send(data);
|
}
|
|
|
|
|
/**
|
* @param d the delimiter
|
* @param p the pattern of your date
|
* @author meizz
|
* @author kimsoft add w+ pattern
|
*/
|
Date.prototype.format = function(style) {
|
var o = {
|
"M+" : this.getMonth() + 1, //month
|
"d+" : this.getDate(), //day
|
"h+" : this.getHours(), //hour
|
"m+" : this.getMinutes(), //minute
|
"s+" : this.getSeconds(), //second
|
"w+" : "\u65e5\u4e00\u4e8c\u4e09\u56db\u4e94\u516d".charAt(this.getDay()), //week
|
"q+" : Math.floor((this.getMonth() + 3) / 3), //quarter
|
"S" : this.getMilliseconds() //millisecond
|
};
|
if (/(y+)/.test(style)) {
|
style = style.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
}
|
for(var k in o){
|
if (new RegExp("("+ k +")").test(style)){
|
style = style.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
|
}
|
}
|
return style;
|
};
|
|
/**
|
* @param d the delimiter
|
* @param p the pattern of your date
|
* @rebuilder kimsoft
|
* @version build 2006.12.15
|
*/
|
String.prototype.toDate = function(delimiter, pattern) {
|
delimiter = delimiter || "-";
|
pattern = pattern || "ymd";
|
var a = this.split(delimiter);
|
var y = parseInt(a[pattern.indexOf("y")], 10);
|
//remember to change this next century ;)
|
if(y.toString().length <= 2) y += 2000;
|
if(isNaN(y)) y = new Date().getFullYear();
|
var m = parseInt(a[pattern.indexOf("m")], 10) - 1;
|
var d = parseInt(a[pattern.indexOf("d")], 10);
|
if(isNaN(d)) d = 1;
|
return new Date(y, m, d);
|
};
|