';for(m=1;m <...]."> How to make an annual calendar using javascript-JS Tutorial-php.cn

How to make an annual calendar using javascript

王林
Release: 2021-11-02 16:35:30
Original
4466 people have browsed it

How to use javascript to make an annual calendar: [function calendar(y){ var w = new Date(y,0).getDay(); var html = '

';for(m =1;m<...>

How to make an annual calendar using javascript

The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

If we need to display specific items of a certain month on a web page, we often need to use the calendar component. Calendar components usually have many ready-made class libraries, so how do we develop a calendar ourselves? The following shows you a very Let’s take a look at the classic calendar component!

HTML:

    制作年历    
Copy after login

calendar.js

function calendar(y){ //获取指定年份1月1日的星期数值 var w = new Date(y,0).getDay(); var html = '
'; //拼接每个月份的表格 for(m=1;m<=12;m++){ html += ''; html += ''; html += '' //获取每个月份共有多少天 var max = new Date(y,m,0).getDate(); html += '';//开始标签 for (d=1;d<=max;d++){ if(w && d== 1){//如果该月的第1天不是星期日,则填充空白 html += ''; } html += ''; if(w == 6 && d != max){//如果星期六不是该月的最后一天,则换行 html += ''; }else if(d==max){//该月的最后一天,闭合标签 html += ''; } w = (w+1>6) ? 0 : w+1; } html += '
' + y + '年' +m+' 月
' +d+ '
'; } html += '
'; return html; }
Copy after login

Final effect:

How to make an annual calendar using javascript

Recommended learning:javascript video tutorial

The above is the detailed content of How to make an annual calendar using javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!