【问题标题】:how i will extract month and year from month year picker,i am using jquery我如何从月份选择器中提取月份和年份,我正在使用 jquery
【发布时间】:2015-07-30 08:48:04
【问题描述】:

我希望月份和年份与这个月/年选择器分开。我试过了。

我想在数据库中插入月份和年份,为此我希望它分开。我正在使用 codeigniter 框架

var month= $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        window.write(' month');

它不工作。

<!--<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">-->
<script src="../monthyear/jquery-ui.js"></script>
<link rel="stylesheet" href="jquery-ui.css">
<label for="monthYearPicker">Date :</label>
<div class="monthYearPicker" name="myDate" ></div>
<!--<input name="myDate" class="monthYearPicker" />-->
     <script>  
$(document).ready(function () {
    $(function () {
        $('.monthYearPicker').datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy'
        }).focus(function () {
            var thisCalendar = $(this);
            $('.ui-datepicker-calendar').detach();
            $('.ui-datepicker-close').click(function () {
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                thisCalendar.datepicker('setDate', new Date(year, month, 1));
            });
        });
    });
});
</script>
<style>
    .ui-datepicker-calendar {
   visibility:hidden;
}</style>

【问题讨论】:

  • “它不工作”是什么意思?
  • 先生,我将如何通过邮寄方式获得月份?
  • 用您面临的实际问题更新您的问题
  • 例如:如果它的显示(pageonload)JULY/2015,我想要 2015 年 7 月和 2015 年的月份;
  • 检查这个:[类似的日期选择器问题][1] [1]:stackoverflow.com/questions/16186386/…

标签: javascript jquery


【解决方案1】:

使用日期选择器的 onClose() 方法。

onClose: function(dateText) { 
           dateVariable = dateText;
           if(dateVariable != null && dateVariable != ""){
                var arr = dateVariable.split(' ');
                $('#month').val(arr[0]);
                $('#year').val(arr[1]);
           }

示例: jsFiddle

希望这能解决你的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 2016-04-05
    相关资源
    最近更新 更多