0

我已经坚持了4个多小时。我只想用箭头选择月份,然后当我按下显示按钮时,ajax 操作将开始(我可以接受)。

示例和代码在这里:

$(function() {
$('.dp').datepicker( {

    changeMonth: false,
    changeYear: false,
    showButtonPanel: false,
    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));
    }
});
});

这是我的jsFiddle

4

2 回答 2

0

您正在寻找的是这个选项:onChangeMonthYear

您可以通过以下方式使用它:

$(function() {
    $('.dp').datepicker( {
        dateFormat: 'dd-mm-yy', 
        onChangeMonthYear: function(year, month) { 
           //you'll get the current year and month selected
           //do whatever you want here with year and month vars
        }
    });
});

更多文档在这里:http ://api.jqueryui.com/datepicker/#option-onChangeMonthYear

于 2013-08-06T12:31:34.140 回答
0
$(function() {
    $('.dp').datepicker( {

        showButtonPanel: false,
        dateFormat: 'mm-yy-dd',

        onChangeMonthYear: function(year,month){
            $('#current').html('Month: '+month+' Year: '+year);
        }
    });

});

http://jsfiddle.net/tSAXf/1/

例如,通过 ajax 发送它您可以将部分代码更改为:

onChangeMonthYear: function(year,month){
    $('#current').html('Month: '+month+' Year: '+year);
    $('#current').attr('rel','month='+month+'&year='+year);
}

并将按钮添加到站点:

<button id="datesubmit">Save this date</button>

以及对此按钮的操作:

$('#datesubmit').click(function(){
    var datesubmit = this;
    if($(datesubmit).attr('Disabled')) return false;
    $(datesubmit).attr('Disabled','Disabled');
    $.post('/my_php_script.php',$('#current').attr('rel'),function(){
        alert('We did it! Date sent!');
        $(datesubmit).removeAttr('Disabled');
    }
});
于 2013-08-06T12:53:10.180 回答