angularjs插件之angular-moment-picker设定可选最小时间和最大时间,以及设置可选时间段

£神魔★判官ぃ 2022-03-12 03:14 207阅读 0赞

效果:初次选择(另外一个时间未选)

  1. -开始时间:最小值没做限制,最大值为当日
  2. -结束时间:最小值没做限制,最大值为当日
  3. 再次次选择(另外一个时间已选)
  4. -开始时间:最小值没做限制,最大值为结束时间最大值
  5. -结束时间:最小值开始时间最小值,最大值为当日

ps:不用多说了,暴力粘贴代码你懂的,代码最后有帮助文档链接

  1. <!DOCTYPE html>
  2. <html ng-app="Demo" style="height:100%;">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>Angular Moment Picker</title>
  8. <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
  9. <link href="https://cdn.bootcss.com/angular-moment-picker/0.10.0/angular-moment-picker.min.css" rel="stylesheet">
  10. </head>
  11. <body ng-cloak style="padding:20px;" ng-controller="DemoController as ctrl">
  12. <div class="form-group">
  13. <label>Start date as string <code></code></label>
  14. <input class="form-control"
  15. placeholder="开始日期"
  16. moment-picker="stringDate"
  17. locale="en"
  18. format="YYYY-MM-DD"
  19. min-date="ctrl.minDate"
  20. max-date="ctrl.maxDate"
  21. start-view="month"
  22. change="ctrl.onChange(newValue, oldValue)"
  23. ng-model="ctrl.first.momentDate"
  24. ng-model-options="{ updateOn: 'blur' }">
  25. </div>
  26. <hr>
  27. <div class="form-group">
  28. <label>Start date as Moment.js object</label>
  29. <input class="form-control"
  30. placeholder="结束日期"
  31. moment-picker="ctrl.second.stringDate"
  32. locale="en"
  33. format="YYYY-MM-DD"
  34. min-date="ctrl.minDate1"
  35. max-date="ctrl.maxDate1"
  36. start-view="month"
  37. change="ctrl.onChange1(newValue, oldValue)"
  38. start-date="ctrl.startDateMoment"
  39. ng-model="ctrl.second.momentDate"
  40. ng-model-options="{ updateOn: 'blur' }">
  41. </div>
  42. <script src="https://cdn.staticfile.org/angular.js/1.6.3/angular.min.js"></script>
  43. <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment-with-locales.js"></script>
  44. <script src="https://cdn.bootcss.com/angular-moment-picker/0.10.0/angular-moment-picker.js"></script>
  45. <script >
  46. angular
  47. .module('Demo', ['moment-picker'])
  48. .controller('DemoController', ['$scope', function () {
  49. var ctrl = this;
  50. // init
  51. ctrl.minDate = "";
  52. ctrl.maxDate = moment();
  53. ctrl.minDate1 = "";
  54. ctrl.maxDate1 = moment();
  55. ctrl.onChange = function (newValue, oldValue) {
  56. ctrl.minDate1 = newValue && newValue.format('YYYY-MM-DD');
  57. };
  58. ctrl.onChange1 = function (newValue, oldValue) {
  59. ctrl.maxDate = newValue && newValue.format('YYYY-MM-DD');
  60. };
  61. }])
  62. </script>
  63. </body>
  64. </html>

插件作者github:https://github.com/indrimuska/angular-moment-picker

在线编辑:https://embed.plnkr.co/

关键属性/方法:min-date,max-date,change

发表评论

表情:
评论列表 (有 0 条评论,207人围观)

还没有评论,来说两句吧...

相关阅读