search
HomeWeb Front-endHTML Tutorial以 “周” 为单位的可以翻页的效果 显示为 2016年第2周_html/css_WEB-ITnose

先上效果图:

动作:向前翻一页,显示为 2016年第1周;向后翻一页,显示为  2016年第3周

动作2:日期与数据关联

html:

<!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <meta http-equiv="X-UA-Compatible" content="IE=edge">        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">        <meta name="apple-mobile-web-app-capable" content="yes">        <meta name="apple-mobile-web-app-status-bar-style" content="black">                    <!--mui-->        <link rel="stylesheet" href="../css/mui.css">        <script src="../js/mui.js"></script>        <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.8.3/jquery.min.js"></script>        <script src="../js/common/common.js"></script>        <script src="../js/chatted_analyse/information_week.js"></script>        <link rel="stylesheet" href="../css/integral_active/integral.active.css">        <style>            .mui-segmented-control.mui-scroll-wrapper .mui-control-item{                padding:0 20px;            }            @media only screen and (min-width: 320px) {                .mui-segmented-control.mui-scroll-wrapper .mui-control-item{                    padding:0 28px;                }            }                @media only screen and (min-width: 360px) {                .mui-segmented-control.mui-scroll-wrapper .mui-control-item{                    padding:0 33px;                }            }                @media only screen and (min-width: 375px) {                .mui-segmented-control.mui-scroll-wrapper .mui-control-item{                    padding:0 38px;                }            }                @media only screen and (min-width: 414px) {                .mui-segmented-control.mui-scroll-wrapper .mui-control-item{                    padding:0 44px;                }            }                .ReportDiv{                width: 100%;                float: left;                height: 300px;                margin-top: 60px;            }            .headerDiv {                background-color: #efeff4;            }        </style>    </head>    <body>        <header class="mui-bar mui-bar-nav">            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>            <h1 id="周聊天消息分析">周聊天消息分析</h1>        </header>        <!--日期的容器-->        <div class="headerDiv">            <div id="previousDiv" class="previousImgDiv"></div>            <div id="nextDiv" class="unNextImgDiv" ></div>            <div id="headerTitleDiv" class="titleDiv"><input id="title" type="text" style="background-color:#f0f0f0;border:none;font-size: 20px;text-align:center;"/></div>        </div>        <!--图表的容器-->        <div id="scroll_view" class="mui-scroll-wrapper" style="top:44px">            <div id="warp" class="mui-scroll">                <div id="emptyDiv" class="emptyDiv" style="display: none;">暂无数据</div>                <div id="pie_information_week" class="ReportDiv"></div>                <div id="bar_information_week" class="ReportDiv"></div>            </div>        </div>            <!--echarts-->    <script src="../js/dist/echarts.js"></script>    <script src="../js/dist/chart/bar.js"></script>    <script src="../js/dist/chart/pie.js"></script>    <script src="../js/dist/echarts-all.js"></script>    </body>    <script type="text/javascript">        mui.init();        mui('.mui-scroll-wrapper').scroll();    </script>    </html>

这么多代码只要看一个地方就OK了,这里有三个DIV,分别是:

previousDiv  上一页ID
nextDiv      下一页ID
<strong>headerTitleDiv 日期容器ID 日期是需要放在input里的, ID为title日期的形式是day, input的type='text',不可以是其它,否则,title不显示日期</strong>
<!--日期的容器-->        <div class="headerDiv">            <div id="previousDiv" class="previousImgDiv"></div>            <div id="nextDiv" class="unNextImgDiv" ></div>            <div id="headerTitleDiv" class="titleDiv"><input id="title" type="text" style="background-color:#f0f0f0;border:none;font-size: 20px;text-align:center;"/></div>        </div>

下面是JS的部分:

1、自定义变量

var previousDiv;var nextDiv;var headerTitleDiv;var title;//拼日期var currentWeek = theWeek();var defaultWeek = theWeek();var currentYear = theYear();var defautlYear = theYear();//监听上一页与下一页的点击事件var previousDivTapEvent;var nextDivTapEvent;

2、变量初始化:

$(document).ready(function(){        previousDiv = document.getElementById('previousDiv');    nextDiv = document.getElementById('nextDiv');    headerTitleDiv = document.getElementById('headerTitleDiv');    title = document.getElementById('title');    title.value = formartWeek();     //给前一页加点击事件,并监听它    previousDiv.addEventListener('tap', previousDivTapEvent);    $(title).on('input', function(){        if(this.value.length == 0){            this.value.length = formartWeek(new Date());        }else{            if(checkCanDoNext()){                fetchDate();                return;            }        }    });    }    

3、前一天监听事件( fetchDate(); 日期与数据关联的方法,调用这个方法,可以取得与日期关联的数据 ):

function previousDivTapEvent(){    resetNextEvent();    nextDiv.className = 'nextImgDiv';    title.value = getPreviousWeek(title.value);    //fetchDate();   日期与数据关联的方法,调用这个方法,可以取得与日期关联的数据    fetchDate();}

4、下一天监听事件:

function nextDivTapEvent(){    resetPreviousEvent();    title.value = getNextWeek();    fetchDate();    if(checkCanDoNext){        nextDiv.removeEventListener('tap',nextDivTapEvent);        return;    }}

5、获取上一周,并返回

function getPreviousWeek(){    //当前周减去一周currentWeek--;    currentWeek--;    if(currentWeek < 1){        currentYear--;        currentWeek = 52;    }    return formartWeek();}

6、获取下一周,并返回

function getNextWeek(){    //当前周加上一周主是下一周    currentWeek ++;    //如果当前周大于52周,满一年,当前年加一年,新的一年,第一周    if(currentWeek > 52){        currentYear ++;        currentWeek = 1;    }    return formartWeek();}

7、判断,如果下一页有数据,则,可以点击进入下一页,如果没有数据,按钮不可点击

function checkCanDoNext(){    if(defaultWeek <= currentWeek && defautlYear <= currentYear){        title.value = formartWeek();        nextDiv.className = 'unNextImgDiv';        nextDiv.removeEventListener('tap',nextDivTapEvent);        return true;    }else{        resetNextEvent();        nextDiv.className = 'nextImgDiv';        return false;    }}

8、重置上一页的监听事件,先给按钮加一个图片class;

先删除原来的事件,再加上新的事件

function resetPreviousEvent(){    previousDiv.className = 'previousImgDiv';    previousDiv.removeEventListener('tap',previousDivTapEvent);    previousDiv.addEventListener('tap',previousDivTapEvent);}

9、重置下一页的监听事件,方法同上

function resetNextEvent(){    nextDiv.className = 'nextImgDiv';    nextDiv.removeEventListener('tap',nextDivTapEvent);    nextDiv.addEventListener('tap',nextDivTapEvent);}

10、格式化日期,以自定义方式返回

function formartWeek(){    return currentYear + "年 第 " + currentWeek + "周";}

11、获取当前年份

function theYear(){    var now = new Date();    years = now.getFullYear();    return years;}

12、获取当前周,并判断是否为闰年,针对2月的天数进行计算

function theWeek(){    var totalDays = 0;    now = new Date();    years = now.getYear()    if (years < 1000)        years += 1900    var days = new Array(12);    days[0] = 31;    days[2] = 31;    days[3] = 30;    days[4] = 31;    days[5] = 30;    days[6] = 31;    days[7] = 31;    days[8] = 30;    days[9] = 31;    days[10] = 30;    days[11] = 31;        //判断是否为闰年,针对2月的天数进行计算    if (Math.round(now.getYear() / 4) == now.getYear() / 4) {        days[1] = 29    } else {        days[1] = 28    }     if (now.getMonth() == 0) {        totalDays = totalDays + now.getDate();    } else {        var curMonth = now.getMonth();        for (var count = 1; count <= curMonth; count++) {            totalDays = totalDays + days[count - 1];        }        totalDays = totalDays + now.getDate();    }    //得到第几周    var week = Math.round(totalDays / 7);    return week;}

以上为周日期的方法,需要注意以下几点:

  1. html中input的类型为text   
    <div id="headerTitleDiv" class="titleDiv"><input id="title" type="text" style="background-color:#f0f0f0;border:none;font-size: 20px;text-align:center;"/></div>

2.  前一页与后一页的点击事件中,可以加入与数据关联的方法,在点击进入下一页时,自动获取相应的数据

3.  给title添加input事件时,需要写一个判断:当前值 = 周日期的返回的方法。如果下一页有数据,才可以点击进入下一页:

$(title).on('input', function(){        if(this.value.length == 0){            this.value.length = formartWeek(new Date());        }else{            if(checkCanDoNext()){                fetchDate();                return;            }        }    });
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.