I would like to share a jquery plug-in, jquery time selector. Thank you for your comments ......

Source: Internet
Author: User

The customer needs to select the time and has not found the solution for a long time, so he wrote a jquery Time Selection control,

The effect is normal. I will continue to improve my learning skills after you make comments ......

First

 

You can configure the start time, end time, and interval and select a time event.

CSS style:

 # Times. Times { Width : 135px ; Overflow : Hidden ; Background : # Fff ; Border : # BBB 1px solid ; Margin :0px ; Padding : 0px ; Position : Absolute ; Z-Index : 99999999 } # Times. Times Li { List-style : None ; Background : # Fff ; Display :Inline-block ; Width : 40px ; Cursor : Pointer ; Margin : 0 1px ; Padding : 0px 1px }

JS script

 /*  * Jquery time plugin 1.0 ** copyright (c) 2013 by Teddy ** QQ: 97081817 mail: 97081817@qq.com ** blog: http://www.cnblogs.com/mybear/  */ (  Function  ($) {$. FN. Extend ({Timer:  Function  (Options ){  VaR Defaults = {interval: 30, minvalue: "00:00", maxvalue: "23:59", onselect: Function  (Date ){}};  VaR Options = $. Extend (defaults, options );  Return   This . Each ( Function (){  New $. Timer ( This  , Options) ;}) ;}, hide:  Function  (){  Return   This . Trigger ("hide" );}})  /*  Input binding event  */  $. Timer = Function (Input, options) {$ (input). BIND ( "Click ", Function  () {Inittimeshtml (input, options); $ (  This ). Trigger ("show" );}). BIND ( "Show ", Function  (Event ){  VaR Offset = $ (Input). offset (); $ ( "# Times" ).Css ({top: Offset. Top +Input. offsetheight, left: Offset. Left}). Show (  False  );}). BIND ( "Hide ", Function  (Event) {$ ( "# Times" Development .css ("display", "NONE" ); $ ( "Body"). Unbind ("mousedown" );})}  /*  Initialize HTML display  */      Function  Inittimeshtml (input, options ){  VaR Result = "" ;  VaR Times = Inittimes (input, options );  For ( VaR I = 0; I <times. length; I ++ ){  If (Times [I] = $ (Input). Val () Result + = "<Li style = \" Background: # a9e4e9 \ ">" + Times [I] + "</LI>" ;  Else  Result + = "<Li onmouseover = \" this. style. background = '# a9e4e9' \ "onmouseout = \" this. style. background = '# fff' \ ">" + Times [I] + "</LI>" ;}  /*  Add the time list to the page  */          If ($ ("# Times"). length> 0 ) {$ ( "# Times" Pai.html (result );}  Else  {$ ( "Body "). append ("<ul id = \" Times \ "class = \" Times \ "style = \" display: None \ ">" + Result + "</ul>" );} /*  Date selection event  */  $ ( "# Times li"). BIND ("click ", Function  (){  VaR Time = $ ( This  ). Text (); options. onselect. Call (input, time); $ (input). Trigger ( "Hide" ). Val (time );});  /*  Automatically hide the pop-up window by clicking somewhere else in the body  */ $ ( "# Times"). Hover ( Function  () {$ ( "Body"). Unbind ("mousedown" );},  Function  () {$ ( 'Body'). BIND ('mousedown ', Function  () {$ ( "Body"). Unbind ("mousedown" ); $ (Input). Trigger ( "Hide" ) ;})}); $ ( 'Body'). BIND ('mousedown ', Function () {$ ( "Body"). Unbind ("mousedown" ); $ (Input). Trigger ( "Hide" );})}  /*  Array of initial time based on the configured minimum and maximum time  */      Function  Inittimes (input, options ){  VaR Times = [];  VaR Mindate = New Date (1990, 10, 01); Mindate. sethours (options. minvalue. Split ( ":") [0], options. minvalue. Split (":") [1 ]);  If (Options. minvalue> Options. maxvalue ){  VaR Maxdate = New Date (1990, 10, 02 );}  Else  {  VaR Maxdate = New Date (1990, 10, 01);} Maxdate. sethours (options. maxvalue. Split ( ":") [0], options. maxvalue. Split (":") [1 ]);  While (Maxdate> mindate | maxdate. gettime () = Mindate. gettime ()){  VaR Time = (mindate. gethours ()> 9? Mindate. gethours (): "0" + mindate. gethours () + ":" + (mindate. getminutes ()> 9? Mindate. getminutes (): "0" + Mindate. getminutes (); times. Push (time); mindate. setminutes (mindate. getminutes () + Options. interval );}  Return Times. Sort () ;}}) (jquery ); 

Demo

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.