【问题标题】:jQuery UI DatePicker month and year in one dropdownjQuery UI DatePicker 月份和年份在一个下拉列表中
【发布时间】:2014-04-14 07:19:18
【问题描述】:

有没有办法在一个下拉菜单中组合月份和年份下拉元素。 新的下拉列表应包含“04/2014”、“05/2014”等元素,直至最大日期。

【问题讨论】:

标签: jquery datepicker customization


【解决方案1】:

这是一种 hacky 方法,但您可以这样做:

changeYearchangeMonth 设置为 false。向正文添加委托的单击侦听器。

$('body').on('click', '#ui-datepicker-title', function() { ... });

在函数主体获取当前年/月的地方,使用所需的值填充自定义 div 并将 div 放置在日期选择器的标题上。

【讨论】:

    【解决方案2】:

    试试这个

    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>jQuery UI Datepicker - Default functionality</title>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
      <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      <link rel="stylesheet" href="/resources/demos/style.css">
      <script>
      $(function() {
        $( "#datepicker" ).datepicker();
      });
      </script>
    </head>
    <body>
    
    <p>Date: <input type="text" id="datepicker"></p>
    
    
    </body>
    </html>
    

    【讨论】:

    • 我的问题是关于自定义/扩展现有 jquery datepicker 而不显示默认 datepicker
    • 使用任何其他插件,如 bootstrap 进行自定义
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多