format.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Format DateTimeSpinner - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Format DateTimeSpinner</h2>
  14. <p>The DataTimeSpinner value can be formatted by specifying the 'formatter' and 'parser' functions.</p>
  15. <div style="margin:20px 0;"></div>
  16. <div class="easyui-panel" style="width:100%;max-width:400px;padding:30px 60px;">
  17. <div style="margin-bottom:20px">
  18. <input class="easyui-datetimespinner" label="mm/dd/yyyy hh:mm" labelPosition="top" value="6/24/2015 17:23" style="width:100%;">
  19. </div>
  20. <div style="margin-bottom:20px">
  21. <input class="easyui-datetimespinner" value="6/24/2015" data-options="label:'mm/dd/yyyy',labelPosition:'top',formatter:formatter1,parser:parser1" style="width:100%;">
  22. </div>
  23. <div style="margin-bottom:20px">
  24. <input class="easyui-datetimespinner" value="2015-6" data-options="label:'yyyy-mm',labelPosition:'top',formatter:formatter2,parser:parser2,selections:[[0,4],[5,7]]" style="width:100%;">
  25. </div>
  26. </div>
  27. <script type="text/javascript">
  28. function formatter1(date){
  29. if (!date){return '';}
  30. return $.fn.datebox.defaults.formatter.call(this, date);
  31. }
  32. function parser1(s){
  33. if (!s){return null;}
  34. return $.fn.datebox.defaults.parser.call(this, s);
  35. }
  36. function formatter2(date){
  37. if (!date){return '';}
  38. var y = date.getFullYear();
  39. var m = date.getMonth() + 1;
  40. return y + '-' + (m<10?('0'+m):m);
  41. }
  42. function parser2(s){
  43. if (!s){return null;}
  44. var ss = s.split('-');
  45. var y = parseInt(ss[0],10);
  46. var m = parseInt(ss[1],10);
  47. if (!isNaN(y) && !isNaN(m)){
  48. return new Date(y,m-1,1);
  49. } else {
  50. return new Date();
  51. }
  52. }
  53. </script>
  54. </body>
  55. </html>