jquery 时间timeselect 插件

/*! * jQuery 1.4.2/1.5.1 timeselect zichenxing,version 1.0.0 * [email protected] ,2011-5-11 * http://blog.csdn.net/wljk506 * Copyright 2011 */(function($) { $.fn.extend({ timeselect: function(options) { var defaults = { // set hours hourid: 'hourid', //ID hourMode: 24, //小时12/24 hourInterval: 1, //间隔 hourDefaultValue: 0, //默认 // set minutes minid: 'minid', //id minLength: 60, //分钟60 minInterval: 1, //间隔 minDefaultValue: 0, //默认inputid:null, //inputiddateid:null, //日期IDdateformat:'H:i' //输出格式Y-m-d H:i或H:i 日期如果不存在默认H:i }; var options = $.extend(defaults, options); return this.each(function() { var o = options; var $this = $(this); var html = Array();var input=$('#'+o.inputid).val();var time='';var date='';if(input&&input.length>0){if(//s/.test(input)){//检测是否是日期+时间格式[2011-05-11 08:10]date=input.replace(//s.*$/,'');//日期time=input.replace(/^.*/s/,'');//时间}else{var re=/^[0-2][0-9]:[0-5][0-9]$/;if(re.test(input)){time=input;}else{return;}}}o.hourDefaultValue=time.replace(/:.*$/,'');o.minDefaultValue=time.replace(/^[0-2][0-9]:/,''); html.push($this.createSel(o.hourid, o.hourMode, o.hourInterval, o.hourDefaultValue)); html.push($this.createSel(o.minid, o.minLength, o.minInterval, o.minDefaultValue)); $this.html(html.join(''));$('#'+this.id+' select.'+o.hourid).change(function(){o.hourDefaultValue=this.value;$this.set(o,date);});$('#'+this.id+' select.'+o.minid).change(function(){o.minDefaultValue=this.value;$this.set(o,date);}); }); } }); $.fn.createSel = function(id, length, interval, defValue) { var h = Array();h.push('<select class="' + id + '" id="' + id + '" name="' + id + '">'); for(i = 0; i < length; i += interval) {var t=i < 10 ? '0' + i : i; h.push('<option value="' + t + '"' + (i == defValue ? ' selected="selected"' : '') + '>' + t + '</option>'); } h.push("</select>"); return h.join(''); }$.fn.set = function(o,d) {var time=o.hourDefaultValue+':'+o.minDefaultValue;if(o.dateformat=='Y-m-d H:i'&&d.length>0){time=d+' '+time;}$('#'+o.inputid).val(time); }})(jQuery);

 

jquery 时间timeselect 插件_第1张图片

你可能感兴趣的:(jquery,Date,function,null,Class,input)