国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

一個完美的日期控件 + 一個用腳本斷判日期型的方法(1)

2024-07-21 02:16:30
字體:
來源:轉載
供稿:網友

1. 一個類似于calendar日期控件,不用再刷新頁面。
2. 判斷文本控件里的值是否能轉換成日期型。

.js 例1:
/*
*coolwindowscalendar.js
*
*/

//------------------------------------------------------------------------------------------------------
var bmoveable=true;
var _versioninfo="原創:walkingpoison;修改者:不人不義;mail: [email protected]" ;
//==================================================== web 頁面顯示部分 =====================================================
var strframe; //存放日歷層的html代碼
document.writeln('<iframe id=meizzdatelayer author=wayx frameborder=0 style="position: absolute; width: 144; height: 211; z-index: 9998; display: none"></iframe>');
strframe='<style>';
strframe+='input.button{border-right: #ff9900 1px solid;border-top: #ff9900 1px solid;border-left: #ff9900 1px solid;';
strframe+='border-bottom: #ff9900 1px solid;background-color: #fff8ec;font-family:宋體;}';
strframe+='td{font-size: 9pt;font-family:宋體;}';
strframe+='</style>';
strframe+='<scr' + 'ipt>';
strframe+='var datelayerx,datelayery; /*存放日歷控件的鼠標位置*/';
strframe+='var bdrag; /*標記是否開始拖動*/';
strframe+='function document.onmousemove() /*在鼠標移動事件中,如果開始拖動日歷,則移動日歷*/';
strframe+='{if(bdrag && window.event.button==1)';
strframe+=' {var datelayer=parent.document.all.meizzdatelayer.style;';
strframe+=' datelayer.posleft += window.event.clientx-datelayerx;/*由于每次移動以后鼠標位置都恢復為初始的位置,因此寫法與div中不同*/';
strframe+=' datelayer.postop += window.event.clienty-datelayery;}}';
strframe+='function dragstart() /*開始日歷拖動*/';
strframe+='{var datelayer=parent.document.all.meizzdatelayer.style;';
strframe+=' datelayerx=window.event.clientx;';
strframe+=' datelayery=window.event.clienty;';
strframe+=' bdrag=true;}';
strframe+='function dragend(){ /*結束日歷拖動*/';
strframe+=' bdrag=false;}';
strframe+='</scr' + 'ipt>';
strframe+='<div style="z-index:9999;position: absolute; left:0; top:0;" onselectstart="return false"><span id=tmpselectyearlayer author=wayx style="z-index: 9999;position: absolute;top: 3; left: 19;display: none"></span>';
strframe+='<span id=tmpselectmonthlayer author=wayx style="z-index: 9999;position: absolute;top: 3; left: 78;display: none"></span>';
strframe+='<table border=1 cellspacing=0 cellpadding=0 width=142 height=160 bordercolor=#ff9900 bgcolor=#ff9900 author="wayx">';
strframe+=' <tr author="wayx"><td width=142 height=23 author="wayx" bgcolor=#ffffff><table border=0 cellspacing=1 cellpadding=0 width=140 author="wayx" height=23>';
strframe+=' <tr align=center author="wayx"><td width=16 align=center bgcolor=#ff9900 style="font-size:12px;cursor: hand;color: #ffffff" ';
strframe+=' onclick="parent.meizzprevm()" title="向前翻 1 月" author=meizz><b author=meizz>&lt;</b>';
strframe+=' </td><td width=60 align=center style="font-size:12px;cursor:default" author=meizz ';
strframe+='onmouseover="style.backgroundcolor=/'#ffd700/'" onmouseout="style.backgroundcolor=/'white/'" ';
strframe+='onclick="parent.tmpselectyearinnerhtml(this.innertext.substring(0,4))" title="點擊這里選擇年份"><span author=meizz id=meizzyearhead></span></td>';
strframe+='<td width=48 align=center style="font-size:12px;cursor:default" author=meizz onmouseover="style.backgroundcolor=/'#ffd700/'" ';
strframe+=' onmouseout="style.backgroundcolor=/'white/'" onclick="parent.tmpselectmonthinnerhtml(this.innertext.length==3?this.innertext.substring(0,1):this.innertext.substring(0,2))"';
strframe+=' title="點擊這里選擇月份"><span id=meizzmonthhead author=meizz></span></td>';
strframe+=' <td width=16 bgcolor=#ff9900 align=center style="font-size:12px;cursor: hand;color: #ffffff" ';
strframe+=' onclick="parent.meizznextm()" title="向后翻 1 月" author=meizz><b author=meizz>&gt;</b></td></tr>';
strframe+=' </table></td></tr>';
strframe+=' <tr author="wayx"><td width=142 height=18 author="wayx">';
strframe+='<table border=1 cellspacing=0 cellpadding=0 bgcolor=#ff9900 ' + (bmoveable? 'onmousedown="dragstart()" onmouseup="dragend()"':'');
strframe+=' bordercolorlight=#ff9900 bordercolordark=#ffffff width=140 height=20 author="wayx" style="cursor:' + (bmoveable ? 'move':'default') + '">';
strframe+='<tr author="wayx" align=center valign=bottom><td style="font-size:12px;color:#ffffff" author=meizz>日</td>';
strframe+='<td style="font-size:12px;color:#ffffff" author=meizz>一</td><td style="font-size:12px;color:#ffffff" author=meizz>二</td>';
strframe+='<td style="font-size:12px;color:#ffffff" author=meizz>三</td><td style="font-size:12px;color:#ffffff" author=meizz>四</td>';
strframe+='<td style="font-size:12px;color:#ffffff" author=meizz>五</td><td style="font-size:12px;color:#ffffff" author=meizz>六</td></tr>';
strframe+='</table></td></tr><!-- author:f.r.huang(meizz) http://www.meizz.com/mail: [email protected] 2002-10-8 -->';
strframe+=' <tr author="wayx"><td width=142 height=120 author="wayx">';
strframe+=' <table border=1 cellspacing=2 cellpadding=0 bordercolorlight=#ff9900 bordercolordark=#ffffff bgcolor=#fff8ec width=140 height=120 author="wayx">';
var n=0; for (j=0;j<5;j++){ strframe+= ' <tr align=center author="wayx">'; for (i=0;i<7;i++){
strframe+='<td width=20 height=20 id=meizzday'+n+' style="font-size:12px" author=meizz onclick=parent.meizzdayclick(this.innertext,0)></td>';n++;}
strframe+='</tr>';}
strframe+=' <tr align=center author="wayx">';
for (i=35;i<39;i++)strframe+='<td width=20 height=20 id=meizzday'+i+' style="font-size:12px" author=wayx onclick="parent.meizzdayclick(this.innertext,0)"></td>';
strframe+=' <td colspan=3 align=right author=meizz><span onclick=parent.closelayer() style="font-size:12px;cursor: hand"';
strframe+=' author=meizz title="' + _versioninfo + '"><u>關閉</u></span>&nbsp;</td></tr>';
strframe+=' </table></td></tr><tr author="wayx"><td author="wayx">';
strframe+=' <table border=0 cellspacing=1 cellpadding=0 width=100% author="wayx" bgcolor=#ffffff>';
strframe+=' <tr author="wayx"><td author=meizz align=left><input author=meizz type=button class=button value="<<" title="向前翻 1 年" onclick="parent.meizzprevy()" ';
strframe+=' onfocus="this.blur()" style="font-size: 12px; height: 20px"><input author=meizz class=button title="向前翻 1 月" type=button ';
strframe+=' value="< " onclick="parent.meizzprevm()" onfocus="this.blur()" style="font-size: 12px; height: 20px"></td><td ';
strframe+=' author=meizz align=center><input author=meizz type=button class=button value=today onclick="parent.meizztoday()" ';
strframe+=' onfocus="this.blur()" title="當前日期" style="font-size: 12px; height: 20px; cursor:hand"></td><td ';
strframe+=' author=meizz align=right><input author=meizz type=button class=button value=" >" onclick="parent.meizznextm()" ';
strframe+=' onfocus="this.blur()" title="向后翻 1 月" class=button style="font-size: 12px; height: 20px"><input ';
strframe+=' author=meizz type=button class=button value=">>" title="向后翻 1 年" onclick="parent.meizznexty()"';
strframe+=' onfocus="this.blur()" style="font-size: 12px; height: 20px"></td>';
strframe+='</tr></table></td></tr></table></div>';

window.frames.meizzdatelayer.document.writeln(strframe);
window.frames.meizzdatelayer.document.close(); //解決ie進度條不結束的問題

//==================================================== web 頁面顯示部分 ======================================================
var outobject;
var outbutton; //點擊的按鈕
var outdate=""; //存放對象的日期
var odatelayer=window.frames.meizzdatelayer.document.all; //存放日歷對象
function setday(tt,obj) //主調函數
{
if (arguments.length > 2){alert("對不起!傳入本控件的參數太多!");return;}
if (arguments.length == 0){alert("對不起!您沒有傳回本控件任何參數!");return;}
var dads = document.all.meizzdatelayer.style;
var th = tt;
var ttop = tt.offsettop; //tt控件的定位點高
var thei = tt.clientheight; //tt控件本身的高
var tleft = tt.offsetleft; //tt控件的定位點寬
var ttyp = tt.type; //tt控件的類型
while (tt = tt.offsetparent){ttop+=tt.offsettop; tleft+=tt.offsetleft;}
dads.top = (ttyp=="image")? ttop+thei : ttop+thei+6;
dads.left = tleft;
outobject = (arguments.length == 1) ? th : obj;
outbutton = (arguments.length == 1) ? null : th; //設定外部點擊的按鈕
//根據當前輸入框的日期顯示日歷的年月
var reg = /^(/d+)-(/d{1,2})-(/d{1,2})$/;
var r = outobject.value.match(reg);
if(r!=null){
r[2]=r[2]-1;
var d= new date(r[1], r[2],r[3]);
if(d.getfullyear()==r[1] && d.getmonth()==r[2] && d.getdate()==r[3]){
outdate=d; //保存外部傳入的日期
}
else outdate="";
meizzsetday(r[1],r[2]+1);
}
else{
outdate="";
meizzsetday(new date().getfullyear(), new date().getmonth() + 1);
}
dads.display = '';

event.returnvalue=false;
}

var monhead = new array(12); //定義陽歷中每個月的最大天數
monhead[0] = 31; monhead[1] = 28; monhead[2] = 31; monhead[3] = 30; monhead[4] = 31; monhead[5] = 30;
monhead[6] = 31; monhead[7] = 31; monhead[8] = 30; monhead[9] = 31; monhead[10] = 30; monhead[11] = 31;

var meizztheyear=new date().getfullyear(); //定義年的變量的初始值
var meizzthemonth=new date().getmonth()+1; //定義月的變量的初始值
var meizzwday=new array(39); //定義寫日期的數組

function document.onclick() //任意點擊時關閉該控件 //ie6的情況可以由下面的切換焦點處理代替
{
with(window.event)
{ if (srcelement.getattribute("author")==null && srcelement != outobject && srcelement != outbutton)
closelayer();
}
}

function document.onkeyup() //按esc鍵關閉,切換焦點關閉
{
if (window.event.keycode==27){
if(outobject)outobject.blur();
closelayer();
}
else if(document.activeelement)
if(document.activeelement.getattribute("author")==null && document.activeelement != outobject && document.activeelement != outbutton)
{
closelayer();
}
}

function meizzwritehead(yy,mm) //往 head 中寫入當前的年與月
{
odatelayer.meizzyearhead.innertext = yy + " 年";
odatelayer.meizzmonthhead.innertext = mm + " 月";
}

function tmpselectyearinnerhtml(stryear) //年份的下拉框
{
if (stryear.match(//d/)!=null){alert("年份輸入參數不是數字!");return;}
var m = (stryear) ? stryear : new date().getfullyear();
if (m < 1000 || m > 9999) {alert("年份值不在 1000 到 9999 之間!");return;}
var n = m - 10;
if (n < 1000) n = 1000;
if (n + 26 > 9999) n = 9974;
var s = "<select author=meizz name=tmpselectyear style='font-size: 12px' "
s += "onblur='document.all.tmpselectyearlayer.style.display=/"none/"' "
s += "onchange='document.all.tmpselectyearlayer.style.display=/"none/";"
s += "parent.meizztheyear = this.value; parent.meizzsetday(parent.meizztheyear,parent.meizzthemonth)'>/r/n";
var selectinnerhtml = s;
for (var i = n; i < n + 26; i++)
{
if (i == m)
{selectinnerhtml += "<option author=wayx value='" + i + "' selected>" + i + "年" + "</option>/r/n";}
else {selectinnerhtml += "<option author=wayx value='" + i + "'>" + i + "年" + "</option>/r/n";}
}
selectinnerhtml += "</select>";
odatelayer.tmpselectyearlayer.style.display="";
odatelayer.tmpselectyearlayer.innerhtml = selectinnerhtml;
odatelayer.tmpselectyear.focus();
}

function tmpselectmonthinnerhtml(strmonth) //月份的下拉框
{
if (strmonth.match(//d/)!=null){alert("月份輸入參數不是數字!");return;}
var m = (strmonth) ? strmonth : new date().getmonth() + 1;
var s = "<select author=meizz name=tmpselectmonth style='font-size: 12px' "
s += "onblur='document.all.tmpselectmonthlayer.style.display=/"none/"' "
s += "onchange='document.all.tmpselectmonthlayer.style.display=/"none/";"
s += "parent.meizzthemonth = this.value; parent.meizzsetday(parent.meizztheyear,parent.meizzthemonth)'>/r/n";
var selectinnerhtml = s;
for (var i = 1; i < 13; i++)
{
if (i == m)
{selectinnerhtml += "<option author=wayx value='"+i+"' selected>"+i+"月"+"</option>/r/n";}
else {selectinnerhtml += "<option author=wayx value='"+i+"'>"+i+"月"+"</option>/r/n";}
}
selectinnerhtml += "</select>";
odatelayer.tmpselectmonthlayer.style.display="";
odatelayer.tmpselectmonthlayer.innerhtml = selectinnerhtml;
odatelayer.tmpselectmonth.focus();
}

function closelayer() //這個層的關閉
{
document.all.meizzdatelayer.style.display="none";
}

function ispinyear(year) //判斷是否閏平年
{
if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;
}

function getmonthcount(year,month) //閏年二月為29天
{
var c=monhead[month-1];if((month==2)&&ispinyear(year)) c++;return c;
}
function getdow(day,month,year) //求某天的星期幾
{
var dt=new date(year,month-1,day).getday()/7; return dt;
}

function meizzprevy() //往前翻 year
{
if(meizztheyear > 999 && meizztheyear <10000){meizztheyear--;}
else{alert("年份超出范圍(1000-9999)!");}
meizzsetday(meizztheyear,meizzthemonth);
}
function meizznexty() //往后翻 year
{
if(meizztheyear > 999 && meizztheyear <10000){meizztheyear++;}
else{alert("年份超出范圍(1000-9999)!");}
meizzsetday(meizztheyear,meizzthemonth);
}
function meizztoday() //today button
{
var today;
meizztheyear = new date().getfullyear();
meizzthemonth = new date().getmonth()+1;
today=new date().getdate();
//meizzsetday(meizztheyear,meizzthemonth);
if(outobject){
outobject.value=meizztheyear + "-" + meizzthemonth + "-" + today;
}
closelayer();
}
function meizzprevm() //往前翻月份
{
if(meizzthemonth>1){meizzthemonth--}else{meizztheyear--;meizzthemonth=12;}
meizzsetday(meizztheyear,meizzthemonth);
}
function meizznextm() //往后翻月份
{
if(meizzthemonth==12){meizztheyear++;meizzthemonth=1}else{meizzthemonth++}
meizzsetday(meizztheyear,meizzthemonth);
}

function meizzsetday(yy,mm) //主要的寫程序**********
{
meizzwritehead(yy,mm);
//設置當前年月的公共變量為傳入值
meizztheyear=yy;
meizzthemonth=mm;

for (var i = 0; i < 39; i++){meizzwday[i]=""}; //將顯示框的內容全部清空
var day1 = 1,day2=1,firstday = new date(yy,mm-1,1).getday(); //某月第一天的星期幾
for (i=0;i<firstday;i++)meizzwday[i]=getmonthcount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1 //上個月的最后幾天
for (i = firstday; day1 < getmonthcount(yy,mm)+1; i++){meizzwday[i]=day1;day1++;}
for (i=firstday+getmonthcount(yy,mm);i<39;i++){meizzwday[i]=day2;day2++}
for (i = 0; i < 39; i++)
{ var da = eval("odatelayer.meizzday"+i) //書寫新的一個月的日期星期排列
if (meizzwday[i]!="")
{
//初始化邊框
da.bordercolorlight="#ff9900";
da.bordercolordark="#ffffff";
if(i<firstday) //上個月的部分
{
da.innerhtml="<b><font color=gray>" + meizzwday[i] + "</font></b>";
da.title=(mm==1?12:mm-1) +"月" + meizzwday[i] + "日";
da.onclick=function("meizzdayclick(this.innertext,-1)");
if(!outdate)
da.style.backgroundcolor = ((mm==1?yy-1:yy) == new date().getfullyear() &&
(mm==1?12:mm-1) == new date().getmonth()+1 && meizzwday[i] == new date().getdate()) ?
"#ffd700":"#e0e0e0";
else
{
da.style.backgroundcolor =((mm==1?yy-1:yy)==outdate.getfullyear() && (mm==1?12:mm-1)== outdate.getmonth() + 1 &&
meizzwday[i]==outdate.getdate())? "#00ffff" :
(((mm==1?yy-1:yy) == new date().getfullyear() && (mm==1?12:mm-1) == new date().getmonth()+1 &&
meizzwday[i] == new date().getdate()) ? "#ffd700":"#e0e0e0");
//將選中的日期顯示為凹下去
if((mm==1?yy-1:yy)==outdate.getfullyear() && (mm==1?12:mm-1)== outdate.getmonth() + 1 &&
meizzwday[i]==outdate.getdate())
{
da.bordercolorlight="#ffffff";
da.bordercolordark="#ff9900";
}
}
}
else if (i>=firstday+getmonthcount(yy,mm)) //下個月的部分
{
da.innerhtml="<b><font color=gray>" + meizzwday[i] + "</font></b>";
da.title=(mm==12?1:mm+1) +"月" + meizzwday[i] + "日";
da.onclick=function("meizzdayclick(this.innertext,1)");
if(!outdate)
da.style.backgroundcolor = ((mm==12?yy+1:yy) == new date().getfullyear() &&
(mm==12?1:mm+1) == new date().getmonth()+1 && meizzwday[i] == new date().getdate()) ?
"#ffd700":"#e0e0e0";
else
{
da.style.backgroundcolor =((mm==12?yy+1:yy)==outdate.getfullyear() && (mm==12?1:mm+1)== outdate.getmonth() + 1 &&
meizzwday[i]==outdate.getdate())? "#00ffff" :
(((mm==12?yy+1:yy) == new date().getfullyear() && (mm==12?1:mm+1) == new date().getmonth()+1 &&
meizzwday[i] == new date().getdate()) ? "#ffd700":"#e0e0e0");
//將選中的日期顯示為凹下去
if((mm==12?yy+1:yy)==outdate.getfullyear() && (mm==12?1:mm+1)== outdate.getmonth() + 1 &&
meizzwday[i]==outdate.getdate())
{
da.bordercolorlight="#ffffff";
da.bordercolordark="#ff9900";
}
}
}
else //本月的部分
{
da.innerhtml="<b>" + meizzwday[i] + "</b>";
da.title=mm +"月" + meizzwday[i] + "日";
da.onclick=function("meizzdayclick(this.innertext,0)"); //給td賦予onclick事件的處理
//如果是當前選擇的日期,則顯示亮藍色的背景;如果是當前日期,則顯示暗黃色背景
if(!outdate)
da.style.backgroundcolor = (yy == new date().getfullyear() && mm == new date().getmonth()+1 && meizzwday[i] == new date().getdate())?
"#ffd700":"#e0e0e0";
else
{
da.style.backgroundcolor =(yy==outdate.getfullyear() && mm== outdate.getmonth() + 1 && meizzwday[i]==outdate.getdate())?
"#00ffff":((yy == new date().getfullyear() && mm == new date().getmonth()+1 && meizzwday[i] == new date().getdate())?
"#ffd700":"#e0e0e0");
//將選中的日期顯示為凹下去
if(yy==outdate.getfullyear() && mm== outdate.getmonth() + 1 && meizzwday[i]==outdate.getdate())
{
da.bordercolorlight="#ffffff";
da.bordercolordark="#ff9900";
}
}
}
da.style.cursor="hand"
}
else{da.innerhtml="";da.style.backgroundcolor="";da.style.cursor="default"}
}
}

function meizzdayclick(n,ex) //點擊顯示框選取日期,主輸入函數*************
{
var yy=meizztheyear;
var mm = parseint(meizzthemonth)+ex; //ex表示偏移量,用于選擇上個月份和下個月份的日期
//判斷月份,并進行對應的處理
if(mm<1){
yy--;
mm=12+mm;
}
else if(mm>12){
yy++;
mm=mm-12;
}

if (mm < 10){mm = "0" + mm;}
if (outobject)
{
if (!n) {//outobject.value="";
return;}
if ( n < 10){n = "0" + n;}
outobject.value= yy + "-" + mm + "-" + n ; //注:在這里你可以輸出改成你想要的格式
outobject.realvalue= yy + "-" + mm + "-" + n ;//與別一個js文件接應 (xpmask.htc) // 囨囚囨図添加 //
closelayer();
}
else {closelayer(); alert("您所要輸出的控件對象并不存在!");}
}
//------------------------------------------------------------------------------------------------------

html 例:
/*
*<script src="../jscript/coolwindowscalendar.js"></script>
*setday(this,[object])和setday(this)
*[object]是控件輸出的控件名
*<input name=txt>
*<input type=button value=setday onclick="setday(this,document.all.txt)">
*<input onfocus="setday(this)">
*/

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 饶平县| 遵义市| 英吉沙县| 崇州市| 陇南市| 江津市| 秦安县| 莲花县| 松滋市| 海伦市| 郁南县| 微山县| 开封市| 志丹县| 巴中市| 乳山市| 靖宇县| 贵溪市| 临朐县| 芮城县| 鄯善县| 和田市| 永新县| 泽库县| 湖州市| 秀山| 若羌县| 五指山市| 信丰县| 凌源市| 海城市| 柘荣县| 永宁县| 武威市| 沅江市| 湖口县| 湖口县| 长岛县| 永兴县| 平度市| 治县。|