下个月和上个月在mozila firefox中不起作用
Next and previous month not working in mozila firefox
我下面的脚本适用于谷歌浏览器,但不适用于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"/>
使用数据属性来保存 Firefox 理解如何解析的日期字符串。
$(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);
});
});
<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" />
相关文章:
- 为什么javascript:void(0)在Firefox中不起作用
- jpm的默认Firefox路径没有'不起作用
- 设置 CSS 背景在 Firefox 中不起作用
- document.getElementById 在 Firefox 中不起作用
- firefox中的CSS动画不起作用
- event.stopPropagation()在firefox javascript中不起作用
- 复选框.onClick在firefox中不起作用
- window.close();在Chrome和Firefox中不起作用
- JQuery在Chrome中不起作用,但Firefox很好
- 选择“行在 Chrome 和 Firefox 中不起作用(生成的代码)”
- Javascript 按键事件在 Firefox 中不起作用
- window.dispatchEvent 在 Firefox、Safari 或 IE 中不起作用
- 更改 Angular 2 中选择的事件在 Firefox 和 Edge 中不起作用
- jQuery SlideToggle() 在 FireFox 中不起作用,在 Chrome 中工作
- 动态关键帧插入在 IE 或 Firefox 上不起作用
- 使用 nameProp 的 JQuery 图像滚动更新在 Firefox 和 Chrome 中不起作用
- Javascript键码在Firefox中不起作用,但在chrome中运行良好
- HTML5<视频>元素在Firefox、Opera和Safari中不起作用
- 输入类型的图像在Internet Explorer中不起作用,但在Chrome和Firefox中起作用
- 使用量角器双击在chrome中效果良好,但在firefox中不起作用