【问题标题】:Jquery Datepicker for month and year onlyJquery Datepicker 仅适用于月份和年份
【发布时间】:2017-02-03 06:05:16
【问题描述】:

我正在开发这个日期选择器。我的代码单独工作正常,但是当我将它与整个应用程序一起使用时,它会在日期标签旁边显示空文本框。我创建了一个plunkr。需要帮助。

由于我的整个代码很大,请check here。这只是我的代码 datepicker.js 中的一个文件:

$(function () {
    $('.date-picker').datepicker({
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'MM yy',
        onClose: function (dateText, inst) {
            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
            $(this).datepicker('setDate', new Date(year, month, 1));
        }
    });
});

【问题讨论】:

    标签: jquery html css datepicker


    【解决方案1】:

    你需要包含这个

    <link rel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    

    脚本:

      $(function() 
      {   $( "#datepicker" ).datepicker({
           changeMonth:true,
           changeYear:true,
           yearRange:"-50:+50",
           dateFormat:"yy-mm-dd" });
       });
    

    还有

    <label>Date</label><input type="text" name="datepicker" id="datepicker"/>
    

    这会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      相关资源
      最近更新 更多