javascript做的日历,完全对象化,望高手提出改进意见。(2/3,将3部分拼成一个html文件浏览)_QQGB.co
this.GetTextDate = function(theString){ //convert a string to a date, if the string is not a date, return a empty string
var i = 0, tmpChar = "", find_tag = "";
var start_at = 0, end_at = 0, year_at = 0, month_at = 0, day_at = 0;
var tmp_at = 0, one_at = 0, two_at = 0, one_days = 0, two_days = 0;
var aryDate = new Array();
var tmpYear = -1, tmpMonth = -1, tmpDay = -1;
var tmpDate = theString.toLowerCase();
var defDate = "";
end_at = tmpDate.length;
for (i=1;i<end_at;i++){
if (tmpDate.charAt(i)=="0"){
tmpChar = tmpDate.charAt(i-1);
if (tmpChar<"0" || tmpChar>"9"){
tmpDate = tmpDate.substr(0,i-1) + "-" + tmpDate.substr(i+1);
}
}
}
for (i=0;i<9;i++){
tmpDate = tmpDate.replace(this.MonthName[i].toLowerCase().substr(0,3), "-00" + (i+1).toString() + "-");
}
for (i=9;i<12;i++){
tmpDate = tmpDate.replace(this.MonthName[i].toLowerCase().substr(0,3), "-0" + (i+1).toString() + "-");
}
tmpDate = tmpDate.replace(/jan/g, "-001-");
tmpDate = tmpDate.replace(/feb/g, "-002-");
tmpDate = tmpDate.replace(/mar/g, "-003-");
tmpDate = tmpDate.replace(/apr/g, "-004-");
tmpDate = tmpDate.replace(/may/g, "-005-");
tmpDate = tmpDate.replace(/jun/g, "-006-");
tmpDate = tmpDate.replace(/jul/g, "-007-");
tmpDate = tmpDate.replace(/aug/g, "-008-");
tmpDate = tmpDate.replace(/sep/g, "-009-");
tmpDate = tmpDate.replace(/oct/g, "-010-");
tmpDate = tmpDate.replace(/nov/g, "-011-");
tmpDate = tmpDate.replace(/dec/g, "-012-");
for (i=0;i<tmpDate.length;i++){
tmpChar = tmpDate.charAt(i);
if ((tmpChar<"0" || tmpChar>"9") && (tmpChar != "-")){
tmpDate = tmpDate.replace(tmpChar,"-")
}
}
while(tmpDate.indexOf("--") != -1){
tmpDate = tmpDate.replace(/--/g,"-");
}
start_at = 0;
end_at = tmpDate.length-1;
while (tmpDate.charAt(start_at)=="-"){
start_at++;
}
while (tmpDate.charAt(end_at)=="-"){
end_at--;
}
if (start_at < end_at+1){
tmpDate = tmpDate.substring(start_at,end_at+1);
}else{
tmpDate = "";
}
aryDate = tmpDate.split("-");
if (aryDate.length != 3){
return(defDate);
}
for (i=0;i<3;i++){
if (parseInt(aryDate[i],10)<1){
aryDate[i] = "1";
}
}
find_tag="000";
for (i=2;i>=0;i--){
if (aryDate[i].length==3){
if (aryDate[i]>="001" && aryDate[i]<="012"){
tmpMonth = parseInt(aryDate[i],10)-1;
switch (i){
case 0:
find_tag = "100";
one_at = parseInt(aryDate[1],10);
two_at = parseInt(aryDate[2],10);
break;
case 1:
find_tag = "010";
one_at = parseInt(aryDate[0],10);
two_at = parseInt(aryDate[2],10);
break;
case 2:
find_tag = "001";
one_at = parseInt(aryDate[0],10);
two_at = parseInt(aryDate[1],10);
break;
}
}
}
}
if (find_tag!="000"){
one_days = this.GetMonthDays(two_at,tmpMonth);
two_days = this.GetMonthDays(one_at,tmpMonth);
if ((one_at>one_days)&&(two_at>two_days)){
return(defDate);
}
if ((one_at<=one_days)&&(two_at>two_days)){
tmpYear = this.GetFormatYear(two_at);
tmpDay = one_at;
本文作者:
«
»