jquery-rockdatepicker.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /**
  2. rockdatepicker 时间选择插件
  3. caratename:chenxihu
  4. caratetime:2014-05-13 21:40:00
  5. email:qqqq2900@126.com
  6. homepage:www.xh829.com
  7. */
  8. (function ($) {
  9. js.onchangedate = function(){}; //选择时间回调
  10. function rockdatepicker(elet, options){
  11. var obj = $(elet);
  12. var can = options;
  13. var rand = js.getrand();
  14. var me = this;
  15. var timeas = null;
  16. this.rand = rand;
  17. this.nY = 2014;//当前月份
  18. this.nm = 5;
  19. this.marr = [31,28,31,30,31,30,31,31,30,31,30,31];
  20. this.weekarr= ['日','一','二','三','四','五','六'];
  21. //初始化
  22. this.init = function(){
  23. this.initdevvalue();
  24. obj[can.trigger](function(){
  25. me.setcontent();
  26. return false;
  27. });
  28. if(can.initshow){
  29. me.setcontent();
  30. };
  31. obj.attr('rockdatepickerbool','true');
  32. if(!can.editable)elet.readOnly =true;
  33. };
  34. this.initdevvalue = function(){
  35. if(can.view=='date')can.format='Y-m-d';
  36. if(can.view=='year')can.format='Y';
  37. if(can.view=='month')can.format='Y-m';
  38. if(can.view=='datetime')can.format='Y-m-d H:i:s';
  39. if(can.view=='time')can.format='H:i:s';
  40. if(can.formats)can.format = can.formats;
  41. var lx = can.format;
  42. if(lx=='H:i:00'||lx=='H:i'||lx=='i:s')can.view='time';
  43. var minv = can.mindate;
  44. if(isempt(minv))minv= obj.attr('mindate');
  45. if(isempt(minv))minv= '1930-01-01 00:00:00';//最小时间
  46. can.mindate = minv;
  47. var maxv = can.maxdate;
  48. if(isempt(maxv))maxv= obj.attr('maxdate');
  49. if(isempt(maxv))maxv= '2050-12-31 23:59:59';//最大时间
  50. can.maxdate = maxv;
  51. this.max = this.shijienges(can.maxdate)
  52. this.min = this.shijienges(can.mindate);
  53. };
  54. this.showtoday = function(){
  55. this.todatetext = this.formdt('now');
  56. this.todate = this.shijienges(this.todatetext);
  57. var val = obj.val();
  58. if(can.inputid!='')val=$('#'+can.inputid+'').val();
  59. if(can.view.indexOf('date')>-1 && val){
  60. if(!this.isdate(val))val = this.todatetext;
  61. }
  62. if(can.view=='time'){
  63. if(val==''){val=js.now('now');}else{val=js.now('Y-m-d')+' '+val;}
  64. }
  65. if(val=='')val = this.formdt(can.view=='datetime' ? 'Y-m-d H:i:00' : can.format, val);
  66. this.nowtext= val;
  67. this.now = this.shijienges(val);
  68. };
  69. this.shijienges = function(sj){
  70. var Y=2014,m=1,d=1,H=0,i=0,s=0,ss1,ss2,ss3,total=0;
  71. ss1 = sj.split(' ');
  72. ss2 = ss1[0].split('-');
  73. Y = parseFloat(ss2[0]);
  74. if(ss2.length>1)m= parseFloat(ss2[1]);
  75. if(ss2.length>2)d= parseFloat(ss2[2]);
  76. if(ss1[1]){
  77. ss3 = ss1[1].split(':');
  78. H = parseFloat(ss3[0]);
  79. i = parseFloat(ss3[1]);
  80. if(ss3.length>2)s= parseFloat(ss3[2]);
  81. }
  82. total = parseFloat(''+Y+''+this.sa(m)+''+this.sa(d)+''+this.sa(H)+''+this.sa(i)+''+this.sa(s)+'');
  83. return {Y:Y,m:m,d:d,H:H,i:i,s:s,total:total};
  84. };
  85. this.sa = function(v){
  86. v = parseFloat(v);
  87. var v1 = ''+v+'';
  88. if(v<10)v1='0'+v+'';
  89. return v1;
  90. };
  91. this.createbasic = function(w, h){
  92. var s= '';
  93. s+= '<div class="rockdatepicker" id="rockdatepicker_'+rand+'" style="width:'+w+'px;height:'+h+'px;overflow:hidden;position:absolute;display:none;"></div>';
  94. $('body').prepend(s);
  95. var oac = $('#rockdatepicker_'+rand+'');
  96. oac.show();
  97. this.setweizhi();
  98. setTimeout(function(){js.addbody(rand, 'remove', 'rockdatepicker_'+rand+''); },100);
  99. return oac;
  100. };
  101. this.setView = function(vis){
  102. can.view = vis;
  103. this.initdevvalue();
  104. };
  105. this.setcontent = function(){
  106. this.showtoday();
  107. $("div[class='rockdatepicker']").remove();
  108. if(can.view =='month' || can.format=='Y-m'){
  109. this.createmontview(1);
  110. return false;
  111. }
  112. if(can.view =='year' || can.format=='Y'){
  113. this.createmontview(0);
  114. return false;
  115. }
  116. var s= '',oi=0,w=270,h=278;
  117. if(can.view!='time'){
  118. s+=' <div style="background:#eeeeee;height:30px;overflow:hidden">';
  119. s+=' <table border="0" width="100%" cellspacing="0" cellpadding="0"><tr>';
  120. s+=' <td style="padding:0px 4px" class="td00" tdaddclick="-y" title="上一年">〈<td>';
  121. s+=' <td height="30" style="padding:0px 5px" nowrap><span class="rockdatepicker_span" id="rockdatepicker_year'+rand+'">2014</span>年<td>';
  122. s+=' <td style="padding:0px 4px" class="td00" tdaddclick="y" title="下一年">〉<td>';
  123. s+=' <td style="padding:0px 2px"><td>';
  124. s+=' <td style="padding:0px 4px" class="td00" tdaddclick="-m" title="上个月">〈<td>';
  125. s+=' <td height="30" style="padding:0px 5px" nowrap><span lass="rockdatepicker_span" id="rockdatepicker_month'+rand+'">06</span>月<td>';
  126. s+=' <td style="padding:0px 4px" class="td00" tdaddclick="m" title="下个月">〉<td>';
  127. s+=' <td style="padding:0px 4px" width="30%">&nbsp;<td>';
  128. s+=' <td style="padding:0px 4px" class="td00" nowrap tdaddclick="today" title="当月">&nbsp;当月&nbsp;<td>';
  129. s+=' </tr></table>';
  130. s+=' </div>';
  131. s+=' <div style="height:188px;overflow:hidden" id="rockdatepicker_table'+rand+'" >';
  132. s+=' <table border="0" class="rockdatepicker_table" style="border-collapse:collapse" width="100%" cellspacing="0" cellpadding="0">';
  133. s+=' <tr height="30" bgcolor="#dedede">';
  134. for(var d=0; d<7; d++){
  135. s+='<td align="center" width="14.28%">'+this.weekarr[d]+'</td>';
  136. }
  137. s+=' </tr>';
  138. for(var r=1; r<=6; r++){
  139. s+='<tr height="26">';
  140. for(var d=1; d<=7; d++){
  141. oi++;
  142. s+='<td align="center" xu="'+oi+'" temp="nr">'+oi+'</td>';
  143. }
  144. s+='</tr>';
  145. }
  146. s+=' </table>';
  147. s+=' </div>';
  148. }else{
  149. s+='<div id="rockdatepicker_table'+rand+'" style="height:140px;overflow:hidden">';
  150. s+='</div>';
  151. w = 220;h=200;
  152. }
  153. s+=' <div style="line-height:30px">&nbsp; <font color="#888888">选择:</font><span id="rockdatepicker_span'+rand+'"></span>';
  154. s+=' <span><input min="0" max="23" onfocus="js.focusval=this.value" onblur="js.number(this)" id="rockdatepicker_input_h'+rand+'" style="width:24px;text-align:center;height:20px;line-height:16px;border:1px #cccccc solid;background:none" value="00" maxlength="2"></span>:';
  155. s+=' <span><input min="0" max="59" onfocus="js.focusval=this.value" onblur="js.number(this)" id="rockdatepicker_input_i'+rand+'" style="width:24px;text-align:center;height:20px;line-height:16px;border:1px #cccccc solid;background:none" value="00" maxlength="2"></span>:';
  156. s+=' <span><input min="0" max="59" onfocus="js.focusval=this.value" onblur="js.number(this)" id="rockdatepicker_input_s'+rand+'" style="width:24px;text-align:center;height:20px;line-height:16px;border:1px #cccccc solid;background:none" value="00" maxlength="2"></span>';
  157. s+= '</div>';
  158. s+=' <div style="height:30px;overflow:hidden;text-align:right;background:#eeeeee;line-height:28px">';
  159. s+=' <a href="javascript:;" class="a" id="rockdatepicker_clear'+rand+'">清空</a>&nbsp; ';
  160. s+=' <a href="javascript:;" class="a" id="rockdatepicker_now'+rand+'">现在</a>&nbsp; ';
  161. s+=' <a href="javascript:;" class="a" id="rockdatepicker_queding'+rand+'">确定</a>&nbsp; ';
  162. s+=' <a href="javascript:;" class="a" id="rockdatepicker_close'+rand+'">关闭</a>&nbsp; ';
  163. s+=' </div>';
  164. var oac = this.createbasic(w,h);
  165. oac.html(s);
  166. this.objtd = oac.find("td[temp='nr']");
  167. oac.find("td[tdaddclick]").click(function(){
  168. me.changedatec($(this));
  169. });
  170. this.objtd.click(function(){
  171. me.tdclick(this);
  172. });
  173. this.setcontentinit();
  174. $('#rockdatepicker_close'+rand+'').click(function(){
  175. me.hidemenu();
  176. });
  177. $('#rockdatepicker_queding'+rand+'').click(function(){
  178. me.queding();
  179. });
  180. $('#rockdatepicker_now'+rand+'').click(function(){
  181. me.quenow();
  182. });
  183. $('#rockdatepicker_clear'+rand+'').click(function(){
  184. me.queclear();
  185. });
  186. $('#rockdatepicker_table'+rand+'').dblclick(function(){
  187. me.queding();
  188. });
  189. $('#rockdatepicker_table'+rand+'').mouseover(function(){
  190. me.hidefudong();
  191. });
  192. if(can.view!='time'){
  193. this.setcontentinit();
  194. this.addcale(this.now.Y, this.now.m);
  195. }else{
  196. $('#rockdatepicker_span'+rand+'').hide();
  197. }
  198. this.shetispannvel(0);
  199. };
  200. this.shetispannvel = function(lx){
  201. $('#rockdatepicker_span'+rand+'').html(''+this.now.Y+'-'+this.sa(this.now.m)+'-'+this.sa(this.now.d)+'');
  202. var ho = $('#rockdatepicker_input_h'+rand+'');
  203. var io = $('#rockdatepicker_input_i'+rand+'');
  204. var so = $('#rockdatepicker_input_s'+rand+'');
  205. ho.val(this.sa(this.now.H));
  206. io.val(this.sa(this.now.i));
  207. so.val(this.sa(this.now.s));
  208. if(can.format.indexOf('H')<0){
  209. get('rockdatepicker_input_h'+rand+'').disabled=true;
  210. }else{
  211. if(lx==0)this.shetispannvelbulr('h');
  212. }
  213. if(can.format.indexOf('i')<0){
  214. get('rockdatepicker_input_i'+rand+'').disabled=true;
  215. }else{
  216. if(lx==0)this.shetispannvelbulr('i');
  217. }
  218. if(can.format.indexOf('s')<0){
  219. get('rockdatepicker_input_s'+rand+'').disabled=true;
  220. }else{
  221. if(lx==0)this.shetispannvelbulr('s');
  222. }
  223. };
  224. this.shetispannvelbulr = function(lx){
  225. var o = $('#rockdatepicker_input_'+lx+''+rand+'');
  226. o.blur(function(){
  227. me.blurnum(this);
  228. });
  229. o.focus(function(){
  230. me.foucsnum(this);
  231. });
  232. };
  233. this.setcontentinit = function(){
  234. $('#rockdatepicker_year'+rand+'').parent().click(function(){
  235. me.changeyear(this);
  236. });
  237. $('#rockdatepicker_month'+rand+'').parent().click(function(){
  238. me.changemonth(this);
  239. });
  240. };
  241. //选择年的
  242. this.changeyear=function(o1){
  243. this.hidefudong();
  244. var o = $(o1);
  245. var off = o.offset();
  246. var s='<div class="rockdatepicker_fudong" id="rockdatepicker_fudong'+rand+'" style="left:'+(off.left-this.mleft-5)+'px;top:'+((off.top-this.mtop)+25)+'px;height:200px;width:70px">';
  247. var xuoi = 0,oi=0;
  248. for(var i=this.max.Y; i>=this.min.Y; i--){
  249. oi++;
  250. var cls= '';
  251. if(i==this.Y){
  252. cls='div01';
  253. xuoi = oi;
  254. }
  255. s+='<div class="'+cls+'">'+i+'</div>';
  256. }
  257. s+='</div>';
  258. $('#rockdatepicker_'+rand+'').append(s);
  259. $('#rockdatepicker_fudong'+rand+'').scrollTop(xuoi*20);
  260. $('#rockdatepicker_fudong'+rand+'').find('div').click(function(){
  261. me.changeyeara(this);
  262. });
  263. };
  264. //选择年的
  265. this.changemonth=function(o1){
  266. this.hidefudong();
  267. var o = $(o1);
  268. var off = o.offset();
  269. var s='<div class="rockdatepicker_fudong" id="rockdatepicker_fudong'+rand+'" style="left:'+(off.left-this.mleft-5)+'px;top:'+((off.top-this.mtop)+25)+'px;height:200px;width:60px">';
  270. var xuoi = 0,oi=0;
  271. for(var i=1; i<=12; i++){
  272. oi++;
  273. var cls= '';
  274. if(i==this.m){
  275. cls='div01';
  276. xuoi = oi;
  277. }
  278. s+='<div class="'+cls+'">'+i+'</div>';
  279. }
  280. s+='</div>';
  281. $('#rockdatepicker_'+rand+'').append(s);
  282. $('#rockdatepicker_fudong'+rand+'').scrollTop(xuoi*20);
  283. $('#rockdatepicker_fudong'+rand+'').find('div').click(function(){
  284. me.changemontha(this);
  285. });
  286. };
  287. this.hidefudong = function(){
  288. $('#rockdatepicker_fudong'+rand+'').remove();
  289. };
  290. this.changeyeara = function(o1){
  291. $('#rockdatepicker_year'+rand+'').html($(o1).html());
  292. this.selchagnge();
  293. };
  294. this.changemontha = function(o1){
  295. $('#rockdatepicker_month'+rand+'').html($(o1).html());
  296. this.selchagnge();
  297. };
  298. this.selchagnge=function(){
  299. var Y=parseFloat($('#rockdatepicker_year'+rand+'').html());
  300. var m=parseFloat($('#rockdatepicker_month'+rand+'').html());
  301. this.addcale(Y,m);
  302. me.hidefudong();
  303. };
  304. this.setweizhi = function(){
  305. var off = obj.offset();;
  306. if(can.inputid != '')off = $('#'+can.inputid+'').offset();
  307. var o = $('#rockdatepicker_'+rand+'');
  308. var nh = get('rockdatepicker_'+rand+'').clientHeight,
  309. nw = get('rockdatepicker_'+rand+'').clientWidth,
  310. t = off.top+can.top,
  311. dy = t+nh-winHb()-$(document).scrollTop(),
  312. l = off.left+can.left,
  313. jl = l+nw-winWb(),
  314. jl1 = 5;
  315. if($('body,html').height()>winHb())jl1=22;
  316. jl=jl+jl1;
  317. if(dy>0)t=t-dy-5;
  318. if(jl>0)l=l-jl;
  319. this.mleft = l;
  320. this.mtop = t;
  321. o.css({'left':''+l+'px','top':''+t+'px'});
  322. };
  323. //单元格单击
  324. this.tdclick = function(o){
  325. var o1 = $(o);
  326. var d = o1.text();
  327. if(isempt(d))return;
  328. this.now.Y = parseFloat(this.Y);
  329. this.now.m = parseFloat(this.m);
  330. this.now.d = parseFloat(d);
  331. this.objtd.removeClass();
  332. this.objtd.addClass('td00');
  333. o.className='td01';
  334. this.shetispannvel(1);
  335. };
  336. //确定
  337. this.queding = function(){
  338. var jg = $('#rockdatepicker_span'+rand+'').html();
  339. if(can.view=='time')jg=js.now('Y-m-d');
  340. var ho = get('rockdatepicker_input_h'+rand+'');
  341. var io = get('rockdatepicker_input_i'+rand+'');
  342. var so = get('rockdatepicker_input_s'+rand+'');
  343. if(ho)if(!ho.disabled)jg+=' '+ho.value+'';
  344. if(io)if(!io.disabled)jg+=':'+io.value+'';
  345. if(so)if(!so.disabled)jg+=':'+so.value+'';
  346. var val = jg;
  347. if(this.isdate(val)){
  348. val=this.formdt(can.format, val);
  349. }
  350. this.setValue(val);
  351. };
  352. this.quenow = function(){
  353. var val = this.formdt(can.format);
  354. this.setValue(val);
  355. };
  356. this.setValue = function(v){
  357. var nobj = false;
  358. if(can.inputid!=''){
  359. nobj = get(can.inputid);
  360. $('#'+can.inputid+'').val(v).focus();;
  361. }else{
  362. nobj = elet;
  363. obj.val(v).focus();;
  364. }
  365. if(nobj){
  366. js.onchangedate(nobj.name, nobj, v, this);
  367. }
  368. can.itemsclick(v, this);
  369. this.hidemenu();
  370. };
  371. this.getValue = function(){
  372. var s = '';
  373. if(can.inputid!=''){
  374. s = $('#'+can.inputid+'').val();;
  375. }else{
  376. s = obj.val();
  377. }
  378. return s;
  379. };
  380. this.queclear = function(){
  381. this.setValue('');
  382. };
  383. //单击
  384. this.itemsclick = function(o,event){
  385. };
  386. this.hidemenu = function(){
  387. $('#rockdatepicker_'+rand+'').remove();
  388. };
  389. this.changedatec= function(o){
  390. var lx = o.attr('tdaddclick');
  391. if(lx=='m'){
  392. this.plftmonth(1);
  393. }
  394. if(lx=='-m'){
  395. this.plftmonth(-1);
  396. }
  397. if(lx=='y'){
  398. this.plftyear(1);
  399. }
  400. if(lx=='-y'){
  401. this.plftyear(-1);
  402. }
  403. if(lx =='today'){
  404. this.addcale(this.todate.Y,this.todate.m);
  405. }
  406. };
  407. //上个月
  408. this.plftmonth=function(lx)
  409. {
  410. var Y=parseFloat(this.Y),m=parseFloat(this.m);
  411. m=m+lx;
  412. if(m==0)m=12;
  413. if(m==13)m=1;
  414. if(m==12&&lx==-1)Y--;
  415. if(m==1&&lx==1)Y++;
  416. this.addcale(Y,m);
  417. };
  418. this.plftyear=function(lx){
  419. var Y=parseFloat(this.Y)+lx;
  420. this.addcale(Y,this.m);
  421. };
  422. this.formdt=function(type,sj){
  423. return js.now(type, sj);
  424. };
  425. this.isdate = function(sj){
  426. if(!sj)return false;
  427. var bo = /^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/.test(sj);
  428. return bo;
  429. };
  430. this.addcale = function(Y,m){
  431. this.objtd.removeClass();
  432. this.objtd.html('');
  433. me.Y=parseFloat(Y);
  434. me.m=parseFloat(m);
  435. var first = ''+Y+'-'+m+'-01';
  436. var stuat = me.formdt('Y-m-w',first);
  437. stuat=stuat.split('-');
  438. var year = parseFloat(stuat[0]);
  439. var month = parseFloat(stuat[1]);
  440. var maxday = me.marr[month-1];//这个月最大天数
  441. if(year%4==0&&month==2)maxday=29;//判断是不是轮年
  442. if(month<10)month='0'+month;
  443. var ic=parseFloat(stuat[2]);
  444. var maic=1;
  445. var xq = 0,nic=ic-1;
  446. var xqarr=[0,0,0,0,0,0,0];
  447. var cls = '';
  448. for(var i=0;i<maxday;i++){
  449. maic=i+ic;
  450. var o = me.objtd[maic];
  451. var d = i+1;
  452. o.innerHTML=''+d+'';
  453. cls = 'td00';
  454. if(d== this.now.d)cls='td01';
  455. o.className = cls;
  456. }
  457. $('#rockdatepicker_year'+rand+'').html(Y);
  458. $('#rockdatepicker_month'+rand+'').html(month);
  459. };
  460. this.focusval = 0;
  461. this.blurnum = function(o){
  462. var o1 = $(o);
  463. var val = o.value;
  464. var mi = parseFloat(o1.attr('min'));
  465. var ma = parseFloat(o1.attr('max'));
  466. if(isNaN(val)||!val)val=this.focusval;
  467. val=parseFloat(val);
  468. if(val<mi)val=mi;
  469. if(val>ma)val=ma;
  470. o.value=this.sa(val);
  471. this.setoutshow=setTimeout("$('#rockdatepicker_spanselfaei"+rand+"').remove();",200);
  472. };
  473. this.foucsnum=function(o){
  474. clearTimeout(this.setoutshow);
  475. this.focusval = o.value;
  476. var o1 = $(o);
  477. var mi = parseFloat(o1.attr('min'));
  478. var ma = parseFloat(o1.attr('max'));
  479. o.select();
  480. $('#rockdatepicker_spanselfaei'+rand+'').remove();
  481. var s='<div style="bottom:52px;position:absolute;right:1px;padding:2px;border:1px #cccccc solid;background-color:#ffffff;font-size:14px;text-align:left" id="rockdatepicker_spanselfaei'+rand+'">';
  482. this.inputhis=o;
  483. for(var a=mi;a<=ma;a++){
  484. var ai = this.sa(a);
  485. if(ai==o.value)ai='<span style="color:#ff0000">'+ai+'</span>';
  486. s+='<font style="margin:2px">'+ai+'</font>';
  487. if((a+1)%10==0)s+='<br>';
  488. }
  489. s+='</div>';
  490. $('#rockdatepicker_'+rand+'').append(s);
  491. $('#rockdatepicker_spanselfaei'+rand+'').find('font').click(function(){
  492. var x = $(this).text();
  493. o.value = x;
  494. });
  495. };
  496. this.createmontview = function(lx){
  497. var w = 220,w1=109;
  498. if(lx==0){
  499. w=130;
  500. w1=w;
  501. }
  502. var oac = this.createbasic(w,270);
  503. var s = '';
  504. s+='<table border="0" width="100%" id="rockdatepicker_table'+rand+'" cellspacing="0" cellpadding="0"><tr valign="top">';
  505. s+=' <td width="'+w1+'"><div align="center" style="line-height:30px;background:#eeeeee"><a href="javascript:" id="rockdatepicker_yearshang'+rand+'" onclick="return false" class="a02">←</a>&nbsp; 年份&nbsp; <a href="javascript:" id="rockdatepicker_yearxia'+rand+'" onclick="return false" class="a02">→</a> </div><div id="rockdatepicker_yearlist'+rand+'" style="line-height:30px;height:180px;overflow:hidden" align="center"></div></td>';
  506. if(lx == 1){
  507. s+=' <td width="2" bgcolor="#cccccc"></td>';
  508. s+=' <td width="109"><div align="center" style="line-height:30px;background:#eeeeee">月份</div><div id="rockdatepicker_monthlist'+rand+'" style="line-height:30px" align="center"></div></td>';
  509. }
  510. s+='</tr></table>';
  511. s+='<div style="line-height:30px">&nbsp; <font color="#888888">选择:</font><span id="rockdatepicker_span'+rand+'">'+this.now.Y+'-0'+this.now.d+'</span></div>';
  512. s+='<div style="height:30px;overflow:hidden;text-align:right;background:#eeeeee;line-height:28px">';
  513. s+=' <a href="javascript:" onclick="return false" class="a" id="rockdatepicker_clear'+rand+'">清空</a>';
  514. s+=' <a href="javascript:" onclick="return false" class="a" id="rockdatepicker_now'+rand+'">现在</a>';
  515. s+=' <a href="javascript:" onclick="return false" class="a" id="rockdatepicker_queding'+rand+'">确定</a>';
  516. s+=' <a href="javascript:" onclick="return false" class="a" id="rockdatepicker_close'+rand+'">关闭</a>';
  517. s+='</div>';
  518. oac.html(s);
  519. $('#rockdatepicker_close'+rand+'').click(function(){
  520. me.hidemenu();
  521. });
  522. $('#rockdatepicker_queding'+rand+'').click(function(){
  523. me.queding();
  524. });
  525. $('#rockdatepicker_now'+rand+'').click(function(){
  526. me.quenow();
  527. });
  528. $('#rockdatepicker_clear'+rand+'').click(function(){
  529. me.queclear();
  530. });
  531. $('#rockdatepicker_yearshang'+rand+'').click(function(){
  532. me.montviewyear(me.montviewyearmin-1,1);
  533. });
  534. $('#rockdatepicker_yearxia'+rand+'').click(function(){
  535. me.montviewyear(me.montviewyearax+1,2);
  536. });
  537. $('#rockdatepicker_table'+rand+'').dblclick(function(){
  538. me.queding();
  539. });
  540. if(lx == 1)this.montviewmonth();
  541. this.montviewyear(this.now.Y,0);
  542. this.showviewffwfwe();
  543. };
  544. this.montviewmonth = function(){
  545. var s = '';
  546. for(var i=1; i<=12; i++){
  547. var oi = ''+i+'';
  548. if(i<10)oi = '0'+i+'';
  549. var cls = 'a02';
  550. if(i==this.now.m)cls='a03';
  551. var deval = parseFloat(''+this.now.Y+''+this.sa(i)+'01000000');
  552. if(deval<this.min.total || deval>this.max.total)cls+=' not';
  553. s+='<a href="javascript:" onclick="return false" class="'+cls+'">'+oi+'月</a> ';
  554. if(i%2==0)s+='<br>';
  555. }
  556. if(s=='')return false;
  557. var oss = $('#rockdatepicker_monthlist'+rand+'');
  558. oss.html(s);
  559. oss.find('a').click(function(){
  560. me.montviewyearcheng(this,1);
  561. });
  562. };
  563. this.montviewyear = function(y,lx){
  564. var min = y - 5;
  565. var max = y + 6;
  566. if(lx==1){
  567. max = y;
  568. min = y-11;
  569. }
  570. if(lx==2){
  571. min = y;
  572. max = y+11;
  573. }
  574. if(min<this.min.Y)min = this.min.Y;
  575. if(max>this.max.Y)max = this.max.Y;
  576. var oi = 0,s='',cls='';
  577. for(var i=min; i<=max; i++){
  578. if(oi==0)this.montviewyearmin = i;
  579. this.montviewyearax = i;
  580. cls = 'a02';
  581. if(i==this.now.Y)cls='a03';
  582. oi++;
  583. s+='<a href="javascript:" onclick="return false" class="'+cls+'">'+i+'</a> ';
  584. if(oi%2==0)s+='<br>';
  585. }
  586. if(s=='')return false;
  587. var oss = $('#rockdatepicker_yearlist'+rand+'');
  588. oss.html(s);
  589. oss.find('a').click(function(){
  590. me.montviewyearcheng(this,0);
  591. });
  592. };
  593. this.montviewyearcheng = function(o1,lx){
  594. if(o1.className.indexOf('not')>-1)return false;
  595. var ossa = $(o1).parent().find('a');
  596. for(var i=0;i<ossa.length;i++){
  597. var cls = ossa[i].className.replace('a03','a02');
  598. ossa[i].className = cls;
  599. }
  600. o1.className='a03';
  601. var val = o1.innerHTML.replace('月','');
  602. if(lx==0){
  603. this.now.Y = parseFloat(val);
  604. if(get('rockdatepicker_monthlist'+rand+''))this.montviewmonth();
  605. }
  606. if(lx==1){
  607. this.now.m = parseFloat(val);
  608. }
  609. this.showviewffwfwe();
  610. };
  611. this.showviewffwfwe=function(){
  612. var m = this.now.m;
  613. var y = this.now.Y;
  614. if(m<10)m='0'+m+'';
  615. var s = ''+y+'-'+m+'';
  616. if(!get('rockdatepicker_monthlist'+rand+''))s=y;
  617. $('#rockdatepicker_span'+rand+'').html(s);
  618. }
  619. };
  620. $.fn.rockdatepicker = function(options){
  621. var defaultVal = {
  622. left:2,top:28,width:0,autohide:true,
  623. itemsclick:function(){},onshow:function(){},initshow:false,removebo:false,
  624. trigger:'click',editable:false,inputid:'',format:'Y-m-d',formats:'',maxdate:'',mindate:'',view:'date'
  625. };
  626. var o = $(this);
  627. if(o.attr('rockdatepickerbool')=='true')return false;
  628. var can = $.extend({}, defaultVal, options);
  629. var aobj = new rockdatepicker(this, can);
  630. aobj.init();
  631. return aobj;
  632. };
  633. })(jQuery);