【问题标题】:How to display the monthpicker in diferent div using Jquery如何使用 Jquery 在不同的 div 中显示月份选择器
【发布时间】:2018-10-26 11:00:46
【问题描述】:

我需要在一个不同的 div 中显示月份选择器 UI,但所选值将使用 Jquery 获取到输入字段。我在下面解释我的代码。

<!DOCTYPE html>
<html>
    <head>
        <title>Parent-Child Communication</title>
        <link rel="stylesheet" type="text/css" href="jquery-ui.min.css" />
        <link rel="stylesheet" type="text/css" href="monthpicker.css" />
        <script src="jquery-2.2.3.min.js"></script>
        <script src="jquery-ui.min.js"></script>
        <script src="monthpicker.min.js"></script>
    </head>
    <body>
        <input id="sDate" type="text" />
        <div id="packagetour_datepickerpick"></div>
        <script type="text/javascript">
            $('#sDate').Monthpicker();
        </script>
    </body>
</html>

这里我需要在&lt;div id="packagetour_datepickerpick"&gt;&lt;/div&gt; 中显示月份选择器,但选择的值应该被提取到输入字段。 (这里是演示代码 )[http://plnkr.co/edit/vtth4dTXTUapFfFQB8MC?p=preview].

【问题讨论】:

标签: jquery monthcalendar


【解决方案1】:

注意:如评论部分所述


我创建了一个使用以下库的运行示例。

  1. https://code.jquery.com/jquery-1.9.1.js
  2. https://code.jquery.com/ui/1.9.2/jquery-ui.js
  3. https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css
  4. https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.css
  5. https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.js

$("#packagetour_datepickerpick").MonthPicker({
    SelectedMonth: '04/' + new Date().getFullYear(),
    AltField: '#sDate',
    OnAfterChooseMonth: function(selectedDate) {
        // Do something with selected JavaScript date.
        // console.log(selectedDate);
    }
});
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css" rel="stylesheet"/>
<link href="https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.css" rel="stylesheet"/>
<script src="https://rawgit.com/KidSysco/jquery-ui-month-picker/v3.0.0/demo/MonthPicker.min.js"></script>


<input id="sDate" type="text" />
<div id="packagetour_datepickerpick"></div>

希望对你有所帮助。 :)

【讨论】:

  • 但它与ui/1.12.1有点不兼容。
  • 可能是,但它与 ui-1.11.4 兼容
  • 它也适用于最新版本的 jQuery UI 1.12.1。我已经更新了我的答案,看看吧
  • bus 添加SelectedMonth: new Date().getMonth()+'/' + new Date().getFullYear() 后获取当前月份,年份在变化。
  • ohh..month 从 0 开始,这就是为什么..任何方式都非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多