js的一套日期控件简单版

        //给入住日期赋初始值为今晚
        window.onload= function(){      
                datecontroller();}


        //2016-04-16需要做一套日期控件了,时间控件
        function datecontroller(){
                curdate = new Date(); 
                var curyear = "20"+(curdate.getYear()-100);
                var curmonth = curdate.getMonth()+1;//变量curmonth是当前的月份
                var curdate = curdate.getDate();//变量curdate是当前的日期
                if(0<curmonth && curmonth<10){
                        if(0<curdate && curdate<10){
                                showdate(curyear,"0"+curmonth,"0"+curdate);
                        }else{
                                showdate(curyear,"0"+curmonth,curdate);
                        }
                }else{
                        if(0<curdate && curdate<10){
                                showdate(curyear,curmonth,"0"+curdate);
                        }else{
                                showdate(curyear,curmonth,curdate);
                        }
                }
        }
        //用作在前端展示日期
        function showdate(curyear,curmonth,curdate){
                document.getElementById("checkindate").value = curyear+"-"+curmonth+"-"+curdate;
                document.getElementById("checkoutdate").value = curyear+"-"+curmonth+"-"+(curdate+1);   
        }


你可能感兴趣的:(js的一套日期控件简单版)