Date Control Implemented by JavaScript
It also reads the current time
<HTML> <br/> <pead> <br/> <style> <br/> <! -- <Br/>. WR {font-size: 12pt; line-Height: 22px} <br/>. wr1 {font-size: 12px; line-Height: 200%} <br/>. wr2 {font-size: 14px; line-Height: 200%} <br/>. wr3 {font-size: 12px} <br/>. wr4 {font-size: 12px; line-height: 150%} <br/> // --> <br/> </style> </P> <p> <title> automatic Date input control </title> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> <br/> </pead> </P> <p> <style type =" text/CSS "> <br/>. date- Picker-WP {<br/> display: none; <br/> position: absolute; <br/> Background: # f1f1f1; <br/> left: 40px; <br/> top: 40px; <br/> border-top: 4px solid #3879d9; <br/>}< br/>. date-picker-WP table {<br/> border: 1px solid # DDD; <br/>}< br/>. date-picker-wp td {<br/> Background: # fafafa; <br/> width: 22px; <br/> Height: 18px; <br/> border: 1px solid # CCC; <br/> font-size: 12px; <br/> text-align: center; <br/>}< br/ >. Date-picker-wp td. noborder {<br/> border: none; <br/> Background: none; <br/>}< br/>. date-picker-wp td a {<br/> color: #1c93c4; <br/> text-Decoration: none; <br/>}< br/>. strong {font-weight: bold} <br/>. hand {cursor: pointer; color: #3879d9} <br/> </style> </P> <p> <SCRIPT type = "text/JavaScript"> <br/> var datepicker = function () {<br/> var $ = function (I) <br/>{< br/> return document. getelementbyid (I) <br/>}, <br/> addevent = function (o, e, f) {o. addeventlistener? O. addeventlistener (E, F, false): O. attachevent ('on' + e, function () {f. call (o)}, <br/> getpos = function (EL) {<br/> for (VAR Pos = {X: 0, Y: 0}; El; el = el. offsetparent) {<br/> POS. X + = el. offsetleft; <br/> POS. Y + = el. offsettop; <br/>}< br/> return Pos; <br/>}; <br/> var init = function (n, config) {<br/> window [N] = This; <br/> date. prototype. _ FD = function () {var d = new date (this); D. setdate (1); R Eturn D. getday () }; <br/> date. prototype. _ fc = function () {var d1 = new date (this), D2 = new date (this); d1.setdate (1); d2.setdate (1); d2.setmonth (d2.getmonth () + 1); Return (d2-d1)/86400000;}; <br/> This. N = N; <br/> This. config = config; <br/> This. D = new date; <br/> This. el = $ (config. inputid); <br/> This. el. title = This. N + 'dateicker'; <br/> This. update (); <br/> This. BIND (); <br/>}; <br/> init. prototype = {<Br/> Update: function (Y, m) {<br/> var con = [], week = ['su ', 'mo', 'tu ', 'We', 'th', 'Fr ', 'sa'], D = This. d, _ this = This; <br/> fn = function (a, B) {return '<TD Title = "' + _ this. N + 'dateicker "class =" noborder hand "onclick =" '+ _ this. N + '. update ('+ A +') "> '+ B +' </TD> '}, <br/> _ html = '<Table cellpadding = 0 cellspacing = 2>'; <br/> Y & D. setyear (D. getfullyear () + Y); <br/> M & D. setmonth (D. getmonth () + M); <Br/> var year = D. getfullyear (), month = D. getmonth () + 1, date = D. getdate (); <br/> for (VAR I = 0; I <Week. length; I ++) con. push ('<TD Title = "' + this. N + 'dateicker "class =" noborder "> '+ week [I] +' </TD> '); <br/> for (VAR I = 0; I <D. _ FD (); I ++) con. push ('<TD Title = "' + this. N + 'dateicker "class =" noborder "> </TD> '); <br/> for (VAR I = 0; I <D. _ FC (); I ++) con. push ('<TD class = "hand" onclick = "' + this. N + '. fillinput (' + Year + ',' + month + ',' + (I + 1) + ') ">' + (I + 1) + '</TD> '); <br/> var toend = con. length % 7; <br/> If (toend! = 0) for (VAR I = 0; I <7-toend; I ++) con. push ('<TD class = "noborder"> </TD>'); <br/> _ HTML + = '<tr>' + FN ("-1, null "," <") + FN (" null,-1 "," <") + '<TD Title ="' + this. N + 'dateicker "colspan = 3 class =" strong "> '+ year +'/'+ month +'/'+ date +' </TD> '+ FN (" null, 1 ","> ") + FN (" 1, null ","> ") + '</tr>'; <br/> for (VAR I = 0; I <con. length; I ++) _ HTML + = (I = 0? '<Tr>': I % 7 = 0? '</Tr> <tr>': '') + con [I] + (I = con. Length-1? '</Tr>': ''); <br/> !! This. Box? This. box. innerhtml = _ HTML: This. createbox (_ html); <br/>}, <br/> fillinput: function (Y, M, d) {<br/> var S = This. config. seprator | '/'; <br/> This. el. value = Y + S + M + S + D; <br/> This. box. style. display = 'none'; <br/>}, <br/> show: function () {<br/> var S = This. box. style, is = This. mask. style; <br/> S ['left'] = is ['left'] = getpos (this. el ). X + 'px'; <br/> S ['top'] = is ['top'] = getpos (this. E L ). Y + this. el. offsetheight + 'px '; <br/> S ['display'] = is ['display'] = 'block '; <br/> is ['width'] = This. box. offsetwidth-2 + 'px '; <br/> is ['height'] = This. box. offsetheight-2 + 'px '; <br/>}, <br/> hide: function () {<br/> This. box. style. display = 'none'; <br/> This. mask. style. display = 'none'; <br/>}, <br/> BIND: function () {<br/> VaR _ this = This; <br/> addevent (document, 'click', function (E) {<Br/> E = E | window. event; <br/> var T = e.tar GET | E. srcelement; <br/> If (T. title! = _ This. N + 'dateicker') {_ this. hide ()} else {_ this. show () }< br/>}); <br/>}, <br/> createbox: function (HTML) {<br/> var box = This. box = document. createelement ('div '), mask = This. mask = document. createelement ('iframe'); <br/> box. classname = This. config. classname | 'dateicker'; <br/> mask. src = 'javascript: false'; <br/> mask. frameborder = 0; <br/> box.style.css text = 'position: absolute; display: none; Z-index: 100'; <br/> mask.style.css text = 'position: absolute; display: none; Z-index: 9998 '; <br/> box. title = This. N + 'dateicker'; <br/> box. innerhtml = HTML; <br/> document. body. appendchild (box); <br/> document. body. appendchild (mask); <br/> return box; <br/>}< br/>}; <br/> return Init; <br/> }(); <br/> onload = function () {<br/> New datepicker ('_ datepicker_demo', {<br/> inputid: 'date-input ', <br/> classname: 'date-picker-WP ', <br/> seprator:'-'<br/> }); <br/>}< br/> </SCRIPT> </P> <p> <body bgcolor = "# ffffdb" text = "#000000" leftmargin = "0" topmargin = "0" marginwidth = "0" marginheight = "0"> <br/> <form> </P> <p> <Table border = "0" width = "60% "align =" center "> </P> <p> <tr> <br/> <TD width =" 45% "class =" wr4 "align =" right "> birthday: </TD> <br/> <TD width = "55%" class = "wr4"> <br/> <input type = "text" name = "mtime" id =" date-input "> <font color =" red "> * </font> <br/> </TD> </P> <p> </tr> </P> <p> <tr> <br/> <TD width = "45%" align = "right"> <input type = "Submit" value = "OK"/> </ TD> <br/> <TD width = "55%"> <input type = "reset" value = "reset"/> </TD> <br/> </tr> <br/> </table> </P> <p> </form> <br/> </body> <br/> </ptml>
JS execution sequence on the HTML page:
1) the first execution in the head label
2) execution in the Body Tag
3) when the onload event is added to the body tag, the corresponding JS is finally executed, that is, when the page is loaded
Note:: When an onload event is added to the body tag, the referenced external JS does not work in the head tag, it can be referenced normally when external JS is referenced inside the body or above