js制作日历

最近在开发过程中,用到了js制作日历。

最终效果

这里写图片描述

插件

RendezVous.js

代码

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>我的微店</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <link rel="stylesheet" href="plugin/bootstrap/css/bootstrap.min.css" />
        <link rel="stylesheet" href="plugin/calendar/rendezvous.css" />
        <link rel="stylesheet" href="css/common.css" />
        <link rel="stylesheet" href="css/index.css" />
        <link rel="stylesheet" href="icons/css/icons.css" />

        <script src="js/jquery-1.10.2.min.js"></script>
        <script src="plugin/bootstrap/js/bootstrap.js"></script>
        <script src="js/util.js"></script>
        <script src="js/index.js"></script>

        <style type="text/css">
            body{background-color: #F5F5F5;}

            /*header start*/
            #header{height: 40px; line-height: 40px;}
            /*header end*/

            /*content start*/
            #content{background-color: #FFFFFF; margin-top: 45px;}
            #goods img{width:100%; height: 80%;}
            .arrow_right{width:7px; height: 12px;}
            #campaign{height: 45px;}
            .campaign{width:20px; height: 20px;}
            #box{height: 45px; line-height: 45px; background-color: #FFFFFF; width:100%;}
            .manage,.add{width:25px;}
            /*content end*/
        </style>
    </head>

    <body>
        <div id="wrapper">
            <div id="header">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-xs-3 col-sm-3 col-centered">
                            <div id="rendez-vous-french"></div>
                            <style>
                                .rendezvous-popup{width:320px;}
                                .rendezvous-datepicker{width:90%;}
                                #rendez-vous-french{width:90px; margin: 0 auto;}
                                #rendez-vous-french input{width:90px; text-align: center; height: 25px; line-height: 25px; border:none;}
                            </style>
                            <script>
                                $(function(){
                                    $("#rendez-vous-french").find("input").attr("value", "添加时间").css({"color":"#000000"});
                                })
                            </script>
                        </div>
                        <div class="col-xs-3 col-sm-3 col-centered">销量</div>
                        <div class="col-xs-3 col-sm-3 col-centered">库存</div>
                        <div class="col-xs-3 col-sm-3 col-righted" style="padding-right: 15px;">
                            <img src="img/myMiniShop/myMiniShop_pic1.png" style="width:20px;"/>
                        </div>
                    </div>
                </div>
            </div>

            <div id="content">
                <div class="container-fluid">
                    <div class="row" style="padding-top: 5px; border-bottom: #FAFAFA 1px solid;">
                        <div class="col-xs-4 col-sm-4 col-centered" id="goods">
                            <img src="img/index/goods3.png"/>
                        </div>
                        <div class="col-xs-7 col-sm-7 col-centered">
                            <div class="row" style="margin-top: 5px;"><div class="col-xs-12 col-sm-12 col-lefted">无印良品MUJI 6角迷你水笔套装(10色)</div></div>
                            <div class="row"><div class="col-xs-12 col-sm-12 col-lefted"><font class="red">&yen;39.00</font></div></div>
                            <div class="row gray" style="margin-top: 22px;">
                                <div class="col-xs-6 col-sm-6 col-lefted">销量 20万</div>
                                <div class="col-xs-6 col-sm-6 col-lefted">收藏 15万</div>
                            </div>
                            <div class="row gray">
                                <div class="col-xs-6 col-sm-6 col-lefted">库存 9999+</div>
                                <div class="col-xs-6 col-sm-6 col-lefted">添加 2016/12/14</div>
                            </div>
                        </div>
                        <div class="col-xs-1 col-sm-1 col-centered">
                            <span class="arrow_right"></span>
                        </div>

                        <script>
                            $(function(){
                                var height = $("#content").children(".container-fluid").children(".row").eq(0).css("height");
//                              console.log(height);
                                $(".arrow_right").parent().css("line-height", height);
                            })
                        </script>
                    </div>
                    <div class="row" id="campaign">
                        <div class="col-xs-3 col-sm-3 col-centered"></div>
                        <div class="col-xs-3 col-sm-3 col-centered gray">
                            <span class="campaign_copy_gray campaign"></span><br />
                            复制
                        </div>
                        <div class="col-xs-3 col-sm-3 col-centered gray">
                            <span class="campaign_link_gray campaign"></span><br />
                            推广
                        </div>
                        <div class="col-xs-3 col-sm-3 col-centered red">
                            <span class="campaign_share_red campaign"></span><br />
                            分享
                        </div>
                    </div>
                </div>
            </div>

            <div id="box">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-xs-6 col-sm-6 col-centered"><img class="manage" src="img/myMiniShop/myMiniShop_pic6.png"/>添加商品</div>
                        <div class="col-xs-6 col-sm-6 col-centered"><img class="add" src="img/myMiniShop/myMiniShop_pic5.png"/>批量管理</div>
                    </div>
                </div>
            </div>

            <!--<script>
                $(function(){
                    var height = ($(window).height() + "").split("px")[0];
                    var footerHeight = ($("#footer").css("height") + "").split("px")[0];
                    var boxHeight = ($("#box").css("height") + "").split("px")[0];
                    $("#box").css("position","fixed").css("top", height - footerHeight - boxHeight + "px");
                    console.log(height - footerHeight - boxHeight + "px");
                })
                window.onresize = function(){
                    var height = ($(window).height() + "").split("px")[0];
                    var footerHeight = ($("#footer").css("height") + "").split("px")[0];
                    var boxHeight = ($("#box").css("height") + "").split("px")[0];
                    $("#box").css("position","fixed").css("top", height - footerHeight - boxHeight + "px");
                    console.log(height - footerHeight - boxHeight + "px");
                }
            </script>-->

            <div id="footer">
                <div class="container-fluid">
                    <div class="row" style="height: 40px; line-height: 32px;">
                        <div class="col-xs-3 col-sm-3 col-centered toggle" id="shop">
                            <div class="redIcon"></div>
                            <div class="red">商城</div>
                        </div>
                        <div class="col-xs-3 col-sm-3 col-centered toggle" id="myShop">
                            <div class="grayIcon"></div>
                            <div class="gray">开店</div>
                        </div>
                        <div class="col-xs-3 col-sm-3 col-centered toggle" id="message">
                            <div class="grayIcon"></div>
                            <div class="gray">消息</div>
                        </div>
                        <div class="col-xs-3 col-sm-3 col-centered toggle" id="member">
                            <div class="grayIcon"></div>
                            <div class="gray">会员</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script src="plugin/calendar/example/js/syntaxhighlighter/shCore.js"></script>
        <script src="plugin/calendar/example/js/syntaxhighlighter/shBrushJScript.js"></script>
        <script src="plugin/calendar/example/js/syntaxhighlighter/shBrushXml.js"></script>
        <script src="plugin/calendar/example/js/syntaxhighlighter/shBrushCss.js"></script>
        <script src="plugin/calendar/rendezvous.js"></script>
        <script src="plugin/calendar/example/js/app.js"></script>
    </body>

</html>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
制作工作日管理日历,您可以使用JavaScript和HTML/CSS。 首先,您需要定义一个包含所有工作日的数组。这可以通过计算从开始日期到结束日期之间的所有日期来完成。 然后,您可以创建一个HTML表格来显示日历。每个单元格可以代表一个日期,并包含一些交互式元素(例如,单击单元格以标记它为工作日或非工作日)。 在JavaScript中,您可以使用事件侦听器来捕获单元格的单击事件,并将其标记为工作日或非工作日。您还可以使用LocalStorage API将这些标记保存在本地存储中,以便在下次访问时恢复它们。 最后,您可以使用CSS样式表来调整日历的外观和感觉,使其看起来更美观和易于使用。 下面是一个简单的示例,用于演示如何使用JavaScript和HTML/CSS制作工作日管理日历。 HTML代码: ```html <!DOCTYPE html> <html> <head> <title>工作日管理日历</title> <link rel="stylesheet" type="text/css" href="calendar.css"> </head> <body> <h1>工作日管理日历</h1> <table id="calendar"> <thead> <tr> <th>周一</th> <th>周二</th> <th>周三</th> <th>周四</th> <th>周五</th> </tr> </thead> <tbody> <tr> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> </tr> <tr> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> </tr> <tr> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> </tr> <tr> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> </tr> <tr> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> <td class="day"></td> </tr> </tbody> </table> <script src="calendar.js"></script> </body> </html> ``` CSS代码: ```css body { font-family: Arial, sans-serif; } h1 { text-align: center; } table { margin: auto; border-collapse: collapse; } th, td { border: 1px solid #ccc; padding: 5px; } .day { cursor: pointer; } .workday { background-color: lightgreen; } .non-workday { background-color: #f2f2f2; } ``` JavaScript代码: ```javascript // 定义开始和结束日期 var startDate = new Date("2022-01-01"); var endDate = new Date("2022-12-31"); // 计算所有工作日 var workdays = []; var currentDate = startDate; while (currentDate <= endDate) { if (currentDate.getDay() !== 0 && currentDate.getDay() !== 6) { workdays.push(new Date(currentDate)); } currentDate.setDate(currentDate.getDate() + 1); } // 获取日历表格和单元格 var calendar = document.getElementById("calendar"); var cells = calendar.getElementsByTagName("td"); // 添加单击事件侦听器以标记工作日或非工作日 for (var i = 0; i < cells.length; i++) { var cell = cells[i]; cell.addEventListener("click", function() { if (this.classList.contains("workday")) { this.classList.remove("workday"); this.classList.add("non-workday"); localStorage.setItem(this.id, "non-workday"); } else if (this.classList.contains("non-workday")) { this.classList.remove("non-workday"); this.classList.add("workday"); localStorage.setItem(this.id, "workday"); } else { this.classList.add("workday"); localStorage.setItem(this.id, "workday"); } }); } // 恢复先前保存的标记 for (var i = 0; i < cells.length; i++) { var cell = cells[i]; var id = cell.cellIndex + "-" + cell.parentNode.rowIndex; var status = localStorage.getItem(id); if (status === "workday") { cell.classList.add("workday"); } else if (status === "non-workday") { cell.classList.add("non-workday"); } } // 将工作日标记为非工作日并禁用它们 for (var i = 0; i < cells.length; i++) { var cell = cells[i]; var date = new Date(startDate); date.setDate(date.getDate() + i); if (date.getDay() === 0 || date.getDay() === 6) { cell.classList.add("non-workday"); cell.removeEventListener("click"); } else { cell.id = cell.cellIndex + "-" + cell.parentNode.rowIndex; } } // 将所有工作日标记为工作日 for (var i = 0; i < workdays.length; i++) { var date = workdays[i]; var cell = cells[date.getDate() - 1]; cell.classList.add("workday"); localStorage.setItem(cell.id, "workday"); } ``` 这将创建一个工作日管理日历,允许用户交互式地标记每个日期是否为工作日或非工作日。它还使用本地存储API来保存标记并在下次访问时恢复它们。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值