Js calculates the number of days of the current month based on the given date Implementation ideas and code

Source: Internet
Author: User

There is nothing in this code. I want to hide the key points in the Code and find them!
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> show date </title>
<Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
Name = "mark ";
Function showLastDate ()
{
Alert (name );
Var reg =/^ \ d {4} \/\ d {1, 2} \/\ d {1, 2} $ /;
Var inputdate = $ ("# indate"). val ();
If (! Reg. test (inputdate ))
{
Alert ("please input date like: 2013/1/14 ");
Return;
}
Var month = parseInt (inputdate. split ("/") [1]);
If (month> 12 | month = 0)
{
Alert ("please input month range from 1-12 ");
Return;
}
Var showdate = getLastDate (inputdate );
$ ("# Lastdate"). val (showdate );
}
Function getLastDate (indate)
{
Alert (name );
Var year = parseInt (indate. split ("/") [0]);
Var month = parseInt (indate. split ("/") [1]);
// Run nian
Var isrun = false;
If (year % 4 = 0 & amp; year % 100! = 0) | year % 400 = 0)
Isrun = true;
Switch (month)
{
Case 2:
If (isrun)
{Return 29 ;}
Else
{Return 28 ;}
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
Return 31;
Default:
Return 30;
}
}
</Script>
</Head>
<Body style = "margin-left: 100px; margin-top: 20px;">
<Br>
Input date: <input id = "indate" type = "text"/> example: 2013/1/14 <br>
<Input type = "button" onclick = "showLastDate ()" value = "Get Last Date"/> <br>
Input date: <input id = "lastdate" type = "text"/> <br>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.