Home > Web Front-end > JS Tutorial > JavaScript implementation page displays the number of days until the 2018 Mid-Autumn Festival

JavaScript implementation page displays the number of days until the 2018 Mid-Autumn Festival

小云云
Release: 2018-02-01 09:54:02
Original
1324 people have browsed it

This article mainly introduces the use of JavaScript to display relevant information on the page to display the number of days until the Mid-Autumn Festival in 2018. Friends who need it can refer to it. You can implement your own functions according to the following code ideas. I hope it can help everyone.

No more nonsense, the specific code is as follows:


##

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>在页面中显示距离2018年中秋节的天数</title>
  <script type="text/javascript">
    function countdown(title,Intime,pId) {
      var online=new Date(Intime); //根据参数定义时间对象
      var now=new Date();   //定义当前系统时间
      var leave=online.getTime()-now.getTime(); //计算时间差
      var day=Math.floor(leave/(1000*60*60*24))+1;
      if (day>1){
          pId.innerHTML="<b>----距离"+title+"还有"+day+"天!<br/>" ; //页面显示信息
      }else{
        if (day==1){
            pId.innerHTML="<b>----明天就是"+title+"啦!<br/>" ; //页面显示信息
        }else{
          if (day==0) {
            pId.innerHTML = "<b>----今天就是" + title + "呀!<br/>"; //页面显示信息
          }else{
              pId.innerHTML="<b>----哎呀!"+title+"已经过了!<br/>" ; //页面显示信息
            }
          }
        }
    }
  </script>
</head>
<body>
  <table width="350" height="450" border="0" align="center" cellspacing="0" cellpadding="0">
    <tr>
      <td valign="bottom">
        <table width="346" height="418" border="0" align="center" cellspacing="0" cellpadding="0">
          <tr>
            <td width="76"></td>
            <td width="270">
              <p id="countDown">
                <b>---</b></p>
                <script type="text/javascript">
                  countdown("2018年中秋节","10/4/2018",countDown); //调用JavaScript函数
                </script>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>
Copy after login

Related recommendations:


PHP Calculate the number of days between dates

JavaScript uses setInterval to implement day countdown and local time

What you must know about JS to get the number of days between dates method


The above is the detailed content of JavaScript implementation page displays the number of days until the 2018 Mid-Autumn Festival. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template