비슷한 것을했지만 라디오 버튼이 있습니다. 희망이 도움이 :
function prevMonth(dt){
var thisMonth = dt.getMonth();
dt.setMonth(thisMonth-1);
if(dt.getMonth() != thisMonth-1 && (dt.getMonth() != 11 || (thisMonth == 11 && dt.getDate() == 1)))
dt.setDate(0);
return dt;
}
:
function reset_last_checkboxes() {
$("#export_last_month").attr("checked", false);
$("#export_3_last_months").attr("checked", false);
$("#export_last_year").attr("checked", false);
}
var date_format = "DD, d MM, yy";
$("#id_from_date").attr("readonly", "readonly");
$("#id_till_date").attr("readonly", "readonly");
$("#id_from_date").datepicker();
$("#id_till_date").datepicker();
$("#id_from_date").change(function() {
$("#id_from_date").datepicker("option", "dateFormat", date_format);
});
$("#id_till_date").change(function() {
$("#id_till_date").datepicker("option", "dateFormat", date_format);
});
$("#id_from_date").click(function() {
reset_last_checkboxes();
});
$("#id_till_date").click(function() {
reset_last_checkboxes();
});
$("#id_till_date").val(format_date(new Date(now)));
$("#export_last_month").click(function(){
var dt = new Date(now);
$("#id_till_date").val(format_date(dt));
$("#id_from_date").val(format_date(prevMonth(dt)));
});
$("#export_3_last_months").click(function(){
var dt = new Date(now);
$("#id_till_date").val(format_date(dt));
$("#id_from_date").val(format_date(prevMonth(prevMonth(prevMonth(dt)))));
});
$("#export_last_year").click(function(){
var dt = new Date(now);
$("#id_till_date").val(format_date(dt));
for (var i=0;i<12;i++) {
dt = prevMonth(dt);
}
$("#id_from_date").val(format_date(dt));
});
당신은 항상 드롭 다운 메뉴를 내 라디오 버튼을 교체하고 그런데 :
나보다이 코드를 더 잘 쓸 수 prevMonth 나는 이런 식으로 계산
환상적이고 감사합니다. : D – craighandley
당신은 환영합니다 :) – alexarsh