我已经坚持了4个多小时。我只想用箭头选择月份然后当我按下show按钮时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。
答案 0 :(得分: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
答案 1 :(得分:0)
$(function() {
$('.dp').datepicker( {
showButtonPanel: false,
dateFormat: 'mm-yy-dd',
onChangeMonthYear: function(year,month){
$('#current').html('Month: '+month+' Year: '+year);
}
});
});
例如,通过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');
}
});