有没有代码简单清晰的 日期选择控件??

解决方案 »

  1.   

    timesheet/////////////////////////////////////////////////////
    function caleTDMove(e){e.style.borderColor="#ffffff #333333 #333333 #ffffff"}
    function caleTDOut(e){e.style.border="solid 1pt #EAF2FF"}
    function hideCale(){popCale.hide()}
    function yearChange(){
    var e=popCale.document.all('yearSel')
    e.options.length=0
    for (i=nYear-4;i<parseInt(nYear)+5;i++){
    e.options.length++
    e.options[e.options.length - 1].value=i
    e.options[e.options.length - 1].text=i
    }
    e.selectedIndex=4
    }
    function CaleClick(e){
    if(isNaN(parseInt(e.innerText))){
    var d=new Date()
    tarObject.value=d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()
    e.style.borderColor="#78ACFF"
    }
    else{tarObject.value=nYear+'-'+(parseInt(nMonth)+1)+'-'+e.innerText
    e.style.borderColor="#EAF2FF"
    }
    popCale.hide()
    }
    function changeYM(e,n){
    if (e.tagName=='SELECT'){
    if(e.value.length==4){nYear=e.value;yearChange()}
    else{nMonth=e.value}
    }
    else{nMonth=parseInt(nMonth)+n
    switch(nMonth){
    case 12:nYear++;nMonth=0;
    yearChange()
    popCale.document.all('monthSel').selectedIndex=0;break;
    case -1:nYear--;nMonth=11;
    yearChange()
    popCale.document.all('monthSel').selectedIndex=11;break;
    default:popCale.document.all('monthSel').selectedIndex=nMonth;break;
    }
    }
    rewriteCale()
    }
      

  2.   

    function rewriteCale(){
    var newTb,newTR,newTD
    newTb=popCale.document.all('LiuzxCale').tBodies[0]
    for (i=0;i<=newTb.rows.length;i++)newTb.deleteRow(2)
    qtyDay=(new Date(nYear,parseInt(nMonth)+1,1) - new Date(nYear,nMonth,1))/24/3600/1000
    fDay=1-(new Date(nYear,nMonth,1).getDay())
    for (i=0;i<42;i++){
    if (i % 7==0)newTR=newTb.insertRow(newTb.rows.length - 2)
    newTD=newTR.insertCell()
    if (fDay>0 && fDay<=qtyDay)newTD.innerText=fDay
    newTD.style.border="solid 1pt #EAF2FF"
    newTD.align='center'
    newTD.onmouseover=Function("caleTDMove(this)")
    newTD.onmouseout=Function("caleTDOut(this)")
    newTD.onclick=Function("CaleClick(this)")
    fDay++
    }
    }
    function isDate(str){
    var reg = /^(\d{4})(-|\/)(0?[1-9]|1[0-2])(-|\/)(0?[1-9]|[12][0-9]|3[01])$/g;
    var r = reg.exec(str);
    if(r==null)return false;
    var d = new Date(r[1], r[3]-1,r[5]);
    var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
    var reg=/(\/|-)(0*)( *)([1-9])/g
    var t=str.replace(reg,'$1$4')
    if (newStr==t)return true;
    return false;
    }
    function getDATE(s){
    tarObject=s
    if ((s.value!='')&&(isDate(s.value))){
    var reg=/(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})/
    var r=reg.exec(s.value);
    nYear=r[1];nMonth=r[3] - 1;
    }
    else{
    var d=new Date()
    nYear=d.getFullYear();nMonth=d.getMonth();
    }
    var e=event.srcElement
    popCale.show(-70,e.clientHeight+5,185,172,e)
    popCale.document.all('monthSel').selectedIndex=nMonth
    yearChange()
    rewriteCale()
    }
    popCale = window.createPopup()
    CaleBody = popCale.document.body
    CaleBody.style.border="outset 1pt #cccccc"
    CaleBody.style.fontSize = "9pt"
    CaleBody.style.backgroundColor= "#EAF2FF"
    CaleBody.style.cursor="hand"
    var d=new Date()
    var nYear=d.getFullYear()
    var nMonth=d.getMonth()
    var arMonth=new Array('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月')
    var qtyDay=(new Date(nYear,parseInt(nMonth)+1,1) - new Date(nYear,nMonth,1))/24/3600/1000
    var strCale='<table bgcolor="#EAF2FF" id="LiuzxCale" author="liuzxit" border="1"'
    strCale+=' bordercolorlight="#0053a6" bordercolordark="#ffffff" cellpadding="1"'
    strCale+=' cellspacing="0" style="font-size:9pt;height:170;cursor:hand;">'
    strCale+='<th bgcolor="#78ACFF" style="color:#0074E5;border:solid 1pt #78ACFF"'
    strCale+=' onclick="parent.changeYM(this,-1)"><<'
    strCale+='<th colspan=2 style="border:solid 1pt #EAF2FF">'
    strCale+='<select id="yearSel" onchange="parent.changeYM(this)" style="font:9pt;"></select>'
    strCale+='<th colspan=3 style="border:solid 1pt #EAF2FF">'
    strCale+='<select id="monthSel" onchange="parent.changeYM(this)" style="font:9pt;">'
    for (i=0;i<12;i++){
    strCale+='<option value='+i+(i==nMonth+1?' selected':'')+'>'+arMonth[i]+'</option>'
    }
    strCale+='</select><th bgcolor="#78ACFF" style="color:#0074E5;border:solid 1pt #78ACFF"'
    strCale+=' onclick="parent.changeYM(this,1)">>></th>'
    strCale+='<tr align=center style="color:#ffffff" bgcolor="#6096BF">'
    strCale+='<td width=22 bgcolor="#80C9FF">日'
    strCale+='<td width=22>一<td width=22>二<td width=22>三<td width=22>四<td width=22>五'
    strCale+='<td width=22 bgcolor="#80C9FF">六</td></tr>'
    var fDay=1-(new Date(nYear,nMonth,1).getDay())
    for (i=0;i<42;i++){
    if (i % 7==0)strCale+='<tr align=center>'
    strCale+='<td style="border:solid 1pt #EAF2FF" onmouseover="caleTDMove(this)"'
    strCale+=' onmouseout="caleTDOut(this)" onclick="CaleClick(this)">'
    strCale+=(fDay>0&&fDay<=qtyDay?fDay:'')+'</td>'
    fDay++
    }
    strCale+='</tr>'
    strCale+='<tr align=center bgcolor="#78ACFF">'
    strCale+='<td style="border:1pt solid #78ACFF">&nbsp;'
    strCale+='<td colspan=2 style="border:1pt solid #78ACFF" onmouseover="parent.caleTDMove(this)"'
    strCale+=' onmouseout="this.style.borderColor=\'#78ACFF\'"'
    strCale+=' onclick="parent.CaleClick(this)">今天'
    strCale+='<td style="border:1pt solid #78ACFF">&nbsp;'
    strCale+='<td colspan=2 style="border:1pt solid #78ACFF"'
    strCale+=' onclick="this.style.borderColor=\'#78ACFF\';parent.hideCale();"'
    strCale+=' onmouseover="parent.caleTDMove(this)"'
    strCale+=' onmouseout="this.style.borderColor=\'#78ACFF\'">关闭'
    strCale+='<td style="border:1pt solid #78ACFF">&nbsp;</td><tr>'
    strCale+='</table>'
    CaleBody.innerHTML=strCale
    yearChange()
      

  3.   

    function CheckNumber(ControlID,ErrorMsg)
    {
    var ControlValue=new String(document.getElementById(ControlID).value);
    if(ControlValue.length==0)
     {alert(ErrorMsg);
     return false;
    }
    for(i=0;i<ControlValue.length;i++)
     {if(!(ControlValue.charCodeAt(i)>=48 && ControlValue.charCodeAt(i)<=58))
     {alert(ErrorMsg);
    return false;
    }
    }
     return true;
    }
    function CheckNumberAndLetter(ControlID,ErrorMsg)
    { var ControlValue=new String(document.getElementById(ControlID).value);
      var i=0;
     var flag=1;
     if(ControlValue.length==0)
     {alert(ErrorMsg);
    return false;
    }
     for(i=0;i<ControlValue.length;i++)
     {var c=ControlValue.charCodeAt(i);
     if( c<48 || (c>58 && c<65) || (c>90 && c<97) || c>122 )
      {alert(ErrorMsg);
     return false;
     }
      }
    return true;
    }
    function CheckLetter(ControlID,ErrorMsg)
    {var ControlValue=new String(document.getElementById(ControlID).value);
    var i=0;
    if(ControlValue.length==0)
     {alert(ErrorMsg);
     return false;
    }
    for(i=0;i<ControlValue.length;i++)
    { var c=ControlValue.charCodeAt(i);
    if(  c<65 ||  (c>90 && c<97) || c>122  )
    {alert(ErrorMsg);
    return false;
    }
     }
    return true;}
    function SetConfirm(msg){return confirm(msg);}
    function SetAlert(msg){return alert(msg);}
    function CheckEmpty(ControlID,ErrorMsg)
    {var ControlValue=new String(document.getElementById(ControlID).value);
    if(ControlValue.length==0)
    {alert(ErrorMsg);
    return false;
    }return true;}
    function CheckDateNoEmpty(ControlID,ErrorMsg)
     {var ControlValue=new String(document.getElementById(ControlID).value);
    var temp=new String(document.getElementById(ControlID).value);
    var i=0;
    if(ControlValue.length<8 || ControlValue.length>10)
    {alert(ErrorMsg);
    return false; 
    }
    if(ControlValue.charAt(4)!="-" || (ControlValue.charAt(6)!="-" && ControlValue.charAt(7)!="-"))
    {alert(ErrorMsg);
    return false;

    var tem=new String(temp.replace("-","0"));
    tem=tem.replace("-","0");
    for(i=0;i<tem.length;i++)
    {if(tem.charCodeAt(i)<48 || tem.charCodeAt(i)>58)
    {alert(ErrorMsg);
    return false;
    }}return true;}
    function CheckFloatAndInt(Control,ErrorMsg)
    { var ControlValue=new String(document.getElementById(Control).value);
     var i=0;var PointAt=0; var PointCount=0;
    for(i=0;i<ControlValue.length;i++)
    {if(ControlValue.charCodeAt(i)==46) 
    {PointAt=i;PointCount=PointCount+1;}}
     if(PointCount==0)
     {for(i=0;i<ControlValue.length;i++)
    if(ControlValue.charCodeAt(i)<48 || ControlValue.charCodeAt(i)>58)
     {alert(ErrorMsg);return false;}return true;}  
    if(PointCount>1){alert(ErrorMsg);return false;}
     if(PointCount=1 && (PointAt==0 || PointAt==ControlValue.length-1)) {alert(ErrorMsg);return false;}
     var temp=new String(ControlValue.replace(".","0"));
     for(i=0;i<temp.length;i++)
     if(temp.charCodeAt(i)<48 || temp.charCodeAt(i)>58)  {alert(ErrorMsg);return false;}
    return true; }
    function CheckPhoneNO(ControlID,ErrorMsg)
    {var ControlValue=new String(document.getElementById(ControlID).value);
    var i=0; var PointCount=0; var PointAt=0;
    if(ControlValue.length==0 || (ControlValue.charAt(0)!="1" && ControlValue.charAt(0)!="0"))
     {alert(ErrorMsg);return false; }
    if(ControlValue.charAt(0)=="1")
     {
    for(i=0;i<ControlValue.length;i++)
    if(ControlValue.charCodeAt(i)<48 || ControlValue.charCodeAt(i)>58 || ControlValue.length!=11 || ControlValue.charAt(1)!="3")
     {alert(ErrorMsg);return false; }
    return true;
     } 
    if(ControlValue.charAt(0)=="0")
    {for(i=0;i<ControlValue.length;i++)
    if(ControlValue.charCodeAt(i)==45){PointCount=PointCount+1;PointAt=i; }  
    if(PointCount!=1 || (PointAt!=3 && PointAt!=4) ){alert(ErrorMsg);return false;}
    var temp=new String(ControlValue.replace("-","0"));
    for(i=0;i<temp.length;i++)
     if(temp.charCodeAt(i)<48  || temp.charCodeAt(i)>58)
     {alert(ErrorMsg);return false;} 
    }
     return true;
     }
    function CheckDate(ControlID,ErrorMsg)
     {var ControlValue=new String(document.getElementById(ControlID).value);
    var temp=new String(document.getElementById(ControlID).value);
    var i=0;
    if(ControlValue.length==0) return true;if(ControlValue.length<8 || ControlValue.length>10)
    {alert(ErrorMsg);
    return false; 
    }
    if(ControlValue.charAt(4)!="-" || (ControlValue.charAt(6)!="-" && ControlValue.charAt(7)!="-"))
    {alert(ErrorMsg);
    return false;

    var tem=new String(temp.replace("-","0"));
    tem=tem.replace("-","0");
    for(i=0;i<tem.length;i++)
    {if(tem.charCodeAt(i)<48 || tem.charCodeAt(i)>58)
    {alert(ErrorMsg);
    return false;
    }}return true;}