【发布时间】:2016-05-26 05:18:36
【问题描述】:
我有这个代码:
$(document).ready(function() {
$('input[name=x_contract]:radio').click(function(){
var date = new Date($("#x_installeddate").val());
if($(this).attr("value")=="Yearly"){
var lastDay = new Date(date.getFullYear(), date.getMonth() + 12, date.getDate());
} else if ($(this).attr("value") == "2 Years") {
var lastDay = new Date(date.getFullYear(), date.getMonth() + 24, date.getDate());
} else if ($(this).attr("value") == "3 Years") {
var lastDay = new Date(date.getFullYear(), date.getMonth() + 36, date.getDate());
}
lastMonth = ( (lastDay.getMonth() + 1) < 10) ? '0' + (lastDay.getMonth() + 1) : (lastDay.getMonth() + 1);
lastDate = ( lastDay.getDate() < 10 ) ? '0' + lastDay.getDate() : lastDay.getDate();
var newDate = lastDay.getFullYear() + '/' + lastMonth + '/' + lastDate;
if (isNaN(lastMonth) == false) $("#x_expirationdate").val(newDate);
});
});
此函数每年、2 年和 3 年生成一个到期日期。在此函数生成到期日期后,我想要更新状态,无论它是否已过期。这取决于当前日期。如果日期已过期,我希望其他列状态为 1,否则为 0。
如何在 JavaScript 中解决这个问题 :) ?
谢谢
【问题讨论】:
-
您好,请您制作一个小提琴/示例。会让别人更容易尝试解决这个问题。
-
您尚未标记任何库或框架,但显然有些正在使用。这样做会很有帮助。
-
lastDay 被声明了 3 次,lastMonth 和 lastDay 根本没有被声明,所以当代码变成全局的运行。
isNaN(lastMonth)什么时候是真的?$("#x_installeddate").val()返回什么值?
标签: javascript validation date status