JavaScript dropdown box Displays current date _ Time date

Source: Internet
Author: User
Tags getdate idate microsoft frontpage

Places to add:

Copy Code code as follows:

<option value= ">2010</option>"
<option value= ">2011</option>"
<option value= ">2012</option>"
<option value= "2013" >2013</option>

Test code:
Copy Code code as follows:

<meta name= "generator" content= "Microsoft FrontPage 6.0" >
<meta name= "ProgId" content= "FrontPage.Editor.Document" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>* the time you spend </title>
<body>
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 0 ">
<tr>
&LT;TD width= "22%" height= "bgcolor=" "F7f7f7" >
<span class= "title_red STYLE2" >* </span> the time you spend
</td>
&LT;TD width= "20%" bgcolor= "F7f7f7" >
<select id= "Years" >
<option value= "2007" >2007</option>
<option value= "2008" >2008</option>
<option value= "2009" >2009</option>
<option value= ">2010</option>"
<option value= ">2011</option>"
<option value= ">2012</option>"
<option value= "2013" >2013</option>
</select> year
</td>
&LT;TD width= "15%" bgcolor= "F7f7f7" >
<select id= "Months" >
<option value= ">01</option>"
<option value= ">02</option>"
<option value= ">03</option>"
<option value= ">04</option>"
<option value= ">05</option>"
<option value= "a" >06</option>
<option value= "Modified" >07</option>
<option value= ">08</option>"
<option value= "a" >09</option>
<option value= "Ten" >10</option>
<option value= "One" >11</option>
<option value= ">12</option>"
</select> Month
</td>
&LT;TD width= "15%" bgcolor= "F7f7f7" >
<select id= "Days" >
<option value= ">01</option>"
<option value= ">02</option>"
<option value= ">03</option>"
<option value= ">04</option>"
<option value= ">05</option>"
<option value= "a" >06</option>
<option value= "Modified" >07</option>
<option value= ">08</option>"
<option value= "a" >09</option>
<option value= "Ten" >10</option>
<option value= "One" >11</option>
<option value= ">12</option>"
<option value= ">13</option>"
<option value= ">14</option>"
<option value= ">15</option>"
<option value= ">16</option>"
<option value= ">17</option>"
<option value= ">18</option>"
<option value= ">19</option>"
<option value= ">20</option>"
<option value= ">21</option>"
<option value= ">22</option>"
<option value= ">23</option>"
<option value= ">24</option>"
<option value= ">25</option>"
<option value= ">26</option>"
<option value= ">27</option>"
<option value= ">28</option>"
<option value= ">29</option>"
<option value= ">30</option>"
<option value= ">31</option>"
</select> Day
</td>
&LT;TD width= "15%" bgcolor= "F7f7f7" >
<select id= "Hours" >
<option value= ">00</option>"
<option value= ">01</option>"
<option value= ">02</option>"
<option value= ">03</option>"
<option value= ">04</option>"
<option value= ">05</option>"
<option value= "a" >06</option>
<option value= "Modified" >07</option>
<option value= ">08</option>"
<option value= "a" >09</option>
<option value= "Ten" >10</option>
<option value= "One" >11</option>
<option value= ">12</option>"
<option value= ">13</option>"
<option value= ">14</option>"
<option value= ">15</option>"
<option value= ">16</option>"
<option value= ">17</option>"
<option value= ">18</option>"
<option value= ">19</option>"
<option value= ">20</option>"
<option value= ">21</option>"
<option value= ">22</option>"
<option value= ">23</option>"
</select> Point
</td>
&LT;TD width= "15%" bgcolor= "F7f7f7" >
<select id= "mins" >
<option value= ">00</option>"
<option value= ">01</option>"
<option value= ">02</option>"
<option value= ">03</option>"
<option value= ">04</option>"
<option value= ">05</option>"
<option value= "a" >06</option>
<option value= "Modified" >07</option>
<option value= ">08</option>"
<option value= "a" >09</option>
<option value= "Ten" >10</option>
<option value= "One" >11</option>
<option value= ">12</option>"
<option value= ">13</option>"
<option value= ">14</option>"
<option value= ">15</option>"
<option value= ">16</option>"
<option value= ">17</option>"
<option value= ">18</option>"
<option value= ">19</option>"
<option value= ">20</option>"
<option value= ">21</option>"
<option value= ">22</option>"
<option value= ">23</option>"
<option value= ">24</option>"
<option value= ">25</option>"
<option value= ">26</option>"
<option value= ">27</option>"
<option value= ">28</option>"
<option value= ">29</option>"
<option value= ">30</option>"
<option value= ">31</option>"
<option value= ">32</option>"
<option value= ">33</option>"
<option value= ">34</option>"
<option value= ">35</option>"
<option value= ">36</option>"
<option value= "Notoginseng" >37</option>
<option value= ">38</option>"
<option value= ">39</option>"
<option value= ">40</option>"
<option value= ">41</option>"
<option value= ">42</option>"
<option value= ">43</option>"
<option value= ">44</option>"
<option value= ">45</option>"
<option value= ">46</option>"
<option value= ">47</option>"
<option value= ">48</option>"
<option value= ">49</option>"
<option value= ">50</option>"
<option value= "Wuyi" >51</option>
<option value= ">52</option>"
<option value= ">53</option>"
<option value= "Si" >54</option>
<option value= ">55</option>"
<option value= ">56</option>"
<option value= ">57</option>"
<option value= ">58</option>"
<option value= ">59</option>"
</select> points
</td>
</tr>
</table>
<script>
var today=new date ()//defines a time object
var yy=today.getyear ()
var mm=today.getmonth () +1
var dd=today.getdate ()
var h=today.gethours ()//define Hours
var m=today.getminutes ()//define Minutes
document.getElementById ("Years"). Options (yy-2007). selected=1
document.getElementById ("months"). Options (mm-1). selected=1
document.getElementById ("Days"). Options (dd-1). selected=1
document.getElementById ("hours"). Options (h). selected=1
document.getElementById ("mins"). Options (m). selected=1
</script>
</body>

The second method: no need to write a good year in advance, scalability is better
<script type= "Text/javascript" >//date drop down box//mutation//2003-9/month number of months (leap years), year, Month month function leapyear, Mo Nth) {switch (parseint (Month)) {case 2:return (year%4 = 0) && (year%100!= 0) | | (year%400 = 0)) ? 29:28; Case 4:case 6:case 9:case 11:return 30; Default:return 31; }//Change days dropdown box, yearobj nianxia Pull Box object, Monthobj month dropdown box object, dayobj the Sun Box object function Changeday (Yearobj, Monthobj, dayobj) {Dayobj.opti ons.length = 0; for (var I=1; I<=leapyear (Yearobj.value, monthobj.value); i++) DayObj.options.add (New Option (I, i)); if (Monthobj.value = = Idate.getmonth () +1 && Yearobj.value = = Idate.getyear ()) Dayobj.selectedindex = Idate.getda Te ()-1; //Build Date the day of the year pull box, you can specify date parameters, no parameters display the current date function Createdateselect (Y, M, d) {document.write (' <select name= iYear1 ' OnChange = "Changeday (this, document.all.iMonth1, document.all.iDay1)" > "); for (var i=100 i>=0; i--) document.write (' <option value= ' + (idate.getyear ()-i) + ' "' + (Idate.getyear ()-i = = y?' Selected ': ' > ' + (idate.getyear ()-i) + ' </option> '); document.write (' </select>  year    '); if (!y) Document.all.iYear1.selectedIndex = 100; document.write (' <select name= "iMonth1" onchange= "Changeday (Document.all.iYear1, this, document.all.iDay1)" > " ); for (var i=1 i<13; i++) document.write (' <option value= ' + i + ' "' + (i = = m? ' selected ': ') + ' > ' + i + ' + Lt;/option> '); document.write (' </select>  month    '); if (!m) Document.all.iMonth1.selectedIndex = Idate.getmonth (); document.write (' <select name= ' IDay1 ">"); for (Var i=1 i<=leapyear (Idate.getyear (), Idate.getmonth () +1), i++) document.write (' <option value= ' + i + ' "' + ( i = = d? ' Selected ': ' + ' > ' + i + ' </option> '); document.write (' </select>  Day '); if (!d) Document.all.iDay1.selectedIndex = Idate.getdate ()-1; var idate = new Date (); Createdateselect (); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The third way: no, but programming ideas can also, if the formal use of the proposed second method
Copy Code code as follows:

<title> New Document </title>
<body>
<script>
function Setday (obj) {
obj = Obj.form;
var years=parseint (Obj.years.options[obj.years.selectedindex].value);
var months=parseint (Obj.months.options[obj.months.selectedindex].value);
if (obj.years.selectedindex==0 | | obj.months.selectedindex==0) return;
var lastday = MonthDay (years,months);
var itemnum = obj.days.length;
if (Lastday-1 < Obj.days.selectedIndex)
{
Obj.days.selectedIndex = lastday-1;
}
Obj.days.length = Lastday;
for (cnt = itemnum + 1;cnt <= lastday;cnt++)
{
Obj.days.options[cnt-1].text = CNT;
}
}
function MonthDay (years,months)
{
var lastday = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
If ((years% 4 = 0) && (years% 100!= 0)) | | (years% 400 = 0))
{
LASTDAY[1] = 29;
}
return lastday[months-1];
}
function Forto (ff,to)
{
document.write (' <option value= ' "></OPTION> ');
for (var ii=ff; ii<=to; ii++)
document.write (' <option value= "' +ii+ '" > ' +ii+ ' </OPTION> ');
}
function A ()
{
Alert (document.all ("Years"). Value+ "Year" +document.all ("months"). Value+ "Month" +document.all ("Days"). Value+ "Day");
}
</script>
<FORM>
<select name= "Years" onchange= "setday (this);" >
<script>forto (1990,2030) </script>
</SELECT> year
<select name= "months" onchange= "setday (this);" >
<script>forto (1,12) </script>
</SELECT> Month
<select name= "Days" ></SELECT> Day
</form>
</body>


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.