Table of Contents
周聊天消息分析
Home Web Front-end HTML Tutorial 以 “周” 为单位的可以翻页的效果 显示为 2016年第2周_html/css_WEB-ITnose

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

Jun 21, 2016 am 09:00 AM

先上效果图:

动作:向前翻一页,显示为 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>
Copy after login

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

previousDiv  上一页ID
Copy after login
nextDiv      下一页ID
Copy after login
<strong>headerTitleDiv 日期容器ID 日期是需要放在input里的, ID为title日期的形式是day, input的type='text',不可以是其它,否则,title不显示日期</strong>
Copy after login
<!--日期的容器-->        <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>
Copy after login

下面是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;
Copy after login

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;            }        }    });    }    
Copy after login

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

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

4、下一天监听事件:

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

5、获取上一周,并返回

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

6、获取下一周,并返回

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

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;    }}
Copy after login

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

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

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

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

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

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

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

11、获取当前年份

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

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;}
Copy after login

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

  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>
    Copy after login

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

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

$(title).on('input', function(){        if(this.value.length == 0){            this.value.length = formartWeek(new Date());        }else{            if(checkCanDoNext()){                fetchDate();                return;            }        }    });
Copy after login
Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

See all articles