【发布时间】:2011-09-13 03:38:00
【问题描述】:
我必须尝试确定隐藏字段中的日期(格式为 mm/dd/yyyy)是否小于今天。如果是,我想让此人知道订阅已过期。我曾在某些情况下工作过,但它并不可靠??
//this is the expiration date that is in a hidden field
var expireDate = $("#expire").val();
//here I am trying to setup a new date for today and change the output to match the date
//format for the hidden field, i.e. mm/dd/yyyy
var a = new Date();
var b = a.toISOString().split("T")[0].split("-");
var ca = b[1] + "/" + b[2] + "/" + b[0];
//now I want to compare the 2 and if the expiration date is less than today, display a warning message
if (expireDate < ca) {
$("<div class=\"message-warning\">This subscription is expired</div>")
.insertAfter("#enddate");
};
【问题讨论】:
-
您似乎试图对两个字符串执行大于比较?难怪它不能可靠地工作。
-
@Alastair - 他们为什么要在这种情况下考虑类型???
-
感谢您指出这一点。为此,您介意就我做错的事情提供帮助吗?
-
@pertrai1 -
#expire中的值是什么样的?是日期的字符串表示形式,例如。13/09/2011? -
请注意,当使用 Javascript(运行客户端)时,有人可以更改他们的系统时钟,这样他们的订阅就永远不会过期。
标签: jquery