Sample Code of a simple JS time control (JS time, minute, and second time control)

Source: Internet
Author: User

I did not find the "hour, minute, and second" control on the Internet for a long time. I made it myself and sent it here for convenience.



Effect of Mouse clicking

SetTime. js
Copy codeThe Code is as follows:
/**//***********************************
* Instructions:
* First, include the control to the page.
* <Script src = "XXX/setTime. js" type = "text/javascript"> </script>
* Control call function: _ SetTime (field)
* For example, <input name = "time" type = "text" onclick = "_ SetTime (this)"/>
*
************************************/
Var str = "";
Document. writeln ("<div id =/" _ contents/"style =/" padding: 6px; background-color: # E3E3E3; font-size: 12px; border: 1px solid #777777; position: absolute; left :? Px; top :? Px; width :? Px; height :? Px; z-index: 1; visibility: hidden/"> ");
Str + = "/u65f6 <select name =/" _ hour/"> ";
For (h = 0; h <= 9; h ++ ){
Str + = "<option value =/" 0 "+ h +"/"> 0" + h + "</option> ";
}
For (h = 10; h <= 23; h ++ ){
Str + = "<option value =/" "+ h +"/">" + h + "</option> ";
}
Str + = "</select>/u5206 <select name =/" _ minute/"> ";
For (m = 0; m <= 9; m ++ ){
Str + = "<option value =/" 0 "+ m +"/"> 0" + m + "</option> ";
}
For (m = 10; m <= 59; m ++ ){
Str + = "<option value =/" "+ m +"/">" + m + "</option> ";
}
Str + = "</select>/u79d2 <select name =/" _ second/"> ";
For (s = 0; s <= 9; s ++ ){
Str + = "<option value =/" 0 "+ s +"/"> 0" + s + "</option> ";
}
For (s = 10; s <= 59; s ++ ){
Str + = "<option value =/" "+ s +"/">" + s + "</option> ";
}
Str + = "</select> <input name =/" queding/"type =/" button/"onclick =/" _ select () /"value =/"/u786e/u5b9a/"style =/" font-size: 12px/"/> </div> ";
Document. writeln (str );
Var _ fieldname;
Function _ SetTime (tt ){
_ Fieldname = tt;
Var ttop = tt. offsetTop; // The positioning height of the TT Control
Var thei = tt. clientHeight; // The height of the TT control itself
Var tleft = tt. offsetLeft; // The positioning point width of the TT Control
While (tt = tt. offsetParent ){
Ttop + = tt. offsetTop;
Tleft + = tt. offsetLeft;
}
Document. all. _ contents. style. top = ttop + thei + 4;
Document. all. _ contents. style. left = tleft;
Document. all. _ contents. style. visibility = "visible ";
}
Function _ select (){
_ Fieldname. value = document. all. _ hour. value + ":" + document. all. _ minute. value + ":" + document. all. _ second. value;
Document. all. _ contents. style. visibility = "hidden ";
}

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.