demo2.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <title>layDate 功能演示二</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>日期时间</cite></a>
  7. </div>
  8. </div>
  9. <div class="layui-fluid">
  10. <div class="layui-row layui-col-space15">
  11. <div class="layui-col-md12">
  12. <div class="layui-card">
  13. <div class="layui-card-header">公历节日和自定义重要日子</div>
  14. <div class="layui-card-body" pad15>
  15. <div class="layui-form" wid100>
  16. <div class="layui-form-item">
  17. <div class="layui-inline">
  18. <label class="layui-form-label">开启公历节日</label>
  19. <div class="layui-input-inline">
  20. <input type="text" class="layui-input" id="test-laydate-mark" placeholder="yyyy-MM-dd">
  21. </div>
  22. </div>
  23. <div class="layui-inline">
  24. <label class="layui-form-label">自定义重要日</label>
  25. <div class="layui-input-inline">
  26. <input type="text" class="layui-input" id="test-laydate-mark-custom" placeholder="yyyy-MM-dd">
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="layui-col-md12">
  35. <div class="layui-card">
  36. <div class="layui-card-header">控制可选的日期与时间</div>
  37. <div class="layui-card-body" pad15>
  38. <div class="layui-form" wid100>
  39. <div class="layui-form-item">
  40. <div class="layui-inline">
  41. <label class="layui-form-label">限定可选日期</label>
  42. <div class="layui-input-inline">
  43. <input type="text" class="layui-input" id="test-laydate-limit1" placeholder="yyyy-MM-dd">
  44. </div>
  45. </div>
  46. <div class="layui-inline">
  47. <label class="layui-form-label">前后若干天可选</label>
  48. <div class="layui-input-inline">
  49. <input type="text" class="layui-input" id="test-laydate-limit2" placeholder="yyyy-MM-dd">
  50. </div>
  51. </div>
  52. <div class="layui-inline">
  53. <label class="layui-form-label">限定可选时间</label>
  54. <div class="layui-input-inline">
  55. <input type="text" class="layui-input" id="test-laydate-limit3" placeholder="HH:mm:ss">
  56. </div>
  57. <div class="layui-form-mid layui-word-aux">
  58. 这里以控制在9:30-17:30为例
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="layui-col-md12">
  67. <div class="layui-card">
  68. <div class="layui-card-header">其它功能示例</div>
  69. <div class="layui-card-body" pad15>
  70. <div class="layui-form" wid100>
  71. <div class="layui-form-item">
  72. <div class="layui-inline">
  73. <label class="layui-form-label">初始赋值</label>
  74. <div class="layui-input-inline">
  75. <input type="text" class="layui-input" id="test-laydate-init-value" placeholder="yyyy-MM-dd">
  76. </div>
  77. </div>
  78. <div class="layui-inline">
  79. <label class="layui-form-label">选中后的回调</label>
  80. <div class="layui-input-inline">
  81. <input type="text" class="layui-input" id="test-laydate-call-done" placeholder="yyyy-MM-dd">
  82. </div>
  83. </div>
  84. <div class="layui-inline">
  85. <label class="layui-form-label">日期切换的回调</label>
  86. <div class="layui-input-inline">
  87. <input type="text" class="layui-input" id="test-laydate-call-change" placeholder="yyyy-MM-dd">
  88. </div>
  89. </div>
  90. <div class="layui-inline">
  91. <label class="layui-form-label">不出现底部栏</label>
  92. <div class="layui-input-inline">
  93. <input type="text" class="layui-input" id="test-laydate-showBottom" placeholder="yyyy-MM-dd">
  94. </div>
  95. </div>
  96. <div class="layui-inline">
  97. <label class="layui-form-label">只出现确定按钮</label>
  98. <div class="layui-input-inline">
  99. <input type="text" class="layui-input" id="test-laydate-confirm" placeholder="yyyy-MM-dd">
  100. </div>
  101. </div>
  102. <div class="layui-inline">
  103. <label class="layui-form-label">自定义事件</label>
  104. <div class="layui-input-inline">
  105. <input type="text" class="layui-input" id="test-laydate-trigger1" placeholder="yyyy-MM-dd">
  106. </div>
  107. </div>
  108. <div class="layui-inline">
  109. <label class="layui-form-label" id="test-laydate-trigger2-1">点我触发</label>
  110. <div class="layui-input-inline">
  111. <input type="text" class="layui-input" id="test-laydate-trigger2" placeholder="yyyy-MM-dd">
  112. </div>
  113. </div>
  114. <div class="layui-inline">
  115. <label class="layui-form-label" id="test-laydate-trigger3-1">双击我触发</label>
  116. <div class="layui-input-inline">
  117. <input type="text" class="layui-input" id="test-laydate-trigger3" placeholder="yyyy-MM-dd">
  118. </div>
  119. </div>
  120. <div class="layui-inline">
  121. <label class="layui-form-label">日期只读</label>
  122. <div class="layui-input-inline">
  123. <input type="text" class="layui-input" id="test-laydate-readonly" readonly="" placeholder="yyyy-MM-dd">
  124. </div>
  125. </div>
  126. <div class="layui-inline">
  127. <label class="layui-form-label">非input元素</label>
  128. <div class="layui-input-inline">
  129. <div id="test-laydate-normElem" style="height: 38px; line-height: 38px; cursor: pointer; border-bottom: 1px solid #e2e2e2;"></div>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <script>
  140. layui.use(['admin', 'laydate'], function(){
  141. var laydate = layui.laydate;
  142. //示例代码
  143. //开启公历节日
  144. laydate.render({
  145. elem: '#test-laydate-mark'
  146. ,calendar: true
  147. });
  148. //自定义重要日
  149. laydate.render({
  150. elem: '#test-laydate-mark-custom'
  151. ,mark: {
  152. '0-10-14': '生日'
  153. ,'0-12-31': '跨年'
  154. ,'0-0-10': '工资'
  155. ,'0-0-15': '月中'
  156. ,'2018-8-8': ''
  157. ,'2099-10-14': '呵呵'
  158. }
  159. ,done: function(value, date){
  160. if(date.year === 2018 && date.month === 8 && date.date === 8){
  161. layer.msg('北京奥运会十周年,时间都去哪儿了');
  162. }
  163. }
  164. });
  165. //限定可选日期
  166. var ins22 = laydate.render({
  167. elem: '#test-laydate-limit1'
  168. ,min: '2016-10-14'
  169. ,max: '2080-10-14'
  170. ,ready: function(){
  171. ins22.hint('日期可选值设定在 <br> 2016-10-14 到 2080-10-14');
  172. }
  173. });
  174. //前后若干天可选,这里以7天为例
  175. laydate.render({
  176. elem: '#test-laydate-limit2'
  177. ,min: -7
  178. ,max: 7
  179. });
  180. //限定可选时间
  181. laydate.render({
  182. elem: '#test-laydate-limit3'
  183. ,type: 'time'
  184. ,min: '09:30:00'
  185. ,max: '17:30:00'
  186. ,btns: ['clear', 'confirm']
  187. });
  188. //初始赋值
  189. laydate.render({
  190. elem: '#test-laydate-init-value'
  191. ,value: '1989-10-14'
  192. });
  193. //选中后的回调
  194. laydate.render({
  195. elem: '#test-laydate-call-done'
  196. ,done: function(value, date){
  197. layer.alert('你选择的日期是:' + value + '<br>获得的对象是' + JSON.stringify(date));
  198. }
  199. });
  200. //日期切换的回调
  201. laydate.render({
  202. elem: '#test-laydate-call-change'
  203. ,change: function(value, date){
  204. layer.msg('你选择的日期是:' + value + '<br><br>获得的对象是' + JSON.stringify(date));
  205. }
  206. });
  207. //不出现底部栏
  208. laydate.render({
  209. elem: '#test-laydate-showBottom'
  210. ,showBottom: false
  211. });
  212. //只出现确定按钮
  213. laydate.render({
  214. elem: '#test-laydate-confirm'
  215. ,btns: ['confirm']
  216. });
  217. //自定义事件
  218. laydate.render({
  219. elem: '#test-laydate-trigger1'
  220. ,trigger: 'mousedown'
  221. });
  222. //点我触发
  223. laydate.render({
  224. elem: '#test-laydate-trigger2'
  225. ,eventElem: '#test-laydate-trigger2-1'
  226. ,trigger: 'click'
  227. });
  228. //双击我触发
  229. lay('#test-laydate-trigger3-1').on('dblclick', function(){
  230. laydate.render({
  231. elem: '#test-laydate-trigger3'
  232. ,show: true
  233. ,closeStop: '#test-laydate-trigger3-1'
  234. });
  235. });
  236. //日期只读
  237. laydate.render({
  238. elem: '#test-laydate-readonly'
  239. ,trigger: 'click'
  240. });
  241. //非input元素
  242. laydate.render({
  243. elem: '#test-laydate-normElem'
  244. });
  245. });
  246. </script>