我将如何提取月和年从月年选择器,我使用jquery

how i will extract month and year from month year picker,i am using jquery

本文关键字:选择器 jquery 提取 何提取      更新时间:2023-09-26

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

我想插入月和年数据库,我想要它分开。我正在使用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>

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

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

示例: jsFiddle

我希望这将解决你的问题。