下个月和上个月没有在mozila firefox中工作

时间:2016-02-09 14:24:00

标签: javascript php jquery

我的脚本正在为谷歌浏览器工作但不适用于Mozilla Firefox。我找不到问题。

$(document).ready(function () {
	var x = 0;
    $("#next").click(function (e) {
    var divs = $('#SelectedMonth').text();
		x++; //or whatever offset
		var CurrentDate = new Date(divs);
		var SelectedMonth=CurrentDate.setMonth(CurrentDate.getMonth() + 1);
		$("#txtDate").val($.datepicker.formatDate('yy-mm  ', new Date(SelectedMonth)));
		$("#SelectedMonth").text($.datepicker.formatDate('MM yy  ', new Date(SelectedMonth)));
    });
	var y = 0;
    $("#prev").click(function (e) {
    var divs = $('#SelectedMonth').text();
		y++; //or whatever offset
		var CurrentDate = new Date(divs);
		var SelectedMonth=CurrentDate.setMonth(CurrentDate.getMonth() - 1);
		$("#txtDate").val($.datepicker.formatDate('yy-mm  ', new Date(SelectedMonth)));
		$("#SelectedMonth").text($.datepicker.formatDate('MM yy  ', new Date(SelectedMonth)));
    });
});
<script src="http://code.jquery.com/jquery-2.1.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<input type="button" value="Pre" id="prev"/><span id="SelectedMonth">January 2016</span><input type="button" value="Next"  id="next"/>

1 个答案:

答案 0 :(得分:0)

使用数据属性来保存Firefox了解如何解析的日期字符串。

&#13;
&#13;
$(document).ready(function() {
  var x = 0;
  $("#next, #prev").click(function(e) {

    var divs = $('#SelectedMonth').data("date"),
        dir = this.id === "next" ? 1 : -1,
        CurrentDate = new Date(divs);
    CurrentDate.setMonth(CurrentDate.getMonth() + dir);
    x += dir;
    $("#txtDate").val($.datepicker.formatDate('yy-mm  ', CurrentDate));
    $("#SelectedMonth")
      .text($.datepicker.formatDate('MM yy  ', CurrentDate))
      .data("date", CurrentDate);

  });

});
&#13;
<script src="http://code.jquery.com/jquery-2.1.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<input type="button" value="Pre" id="prev" /><span id="SelectedMonth" data-date="01/01/2013">January 2016</span>
<input type="button" value="Next" id="next" />
&#13;
&#13;
&#13;