[英]Populate Image Based on Start Date / End Date
I will try to be as specific as possible. 我将尝试尽可能具体。 I've completely confused myself with everything I've tried, so hopefully someone will be able to help me out.
我对自己所做的一切完全感到困惑,因此希望有人能够帮助我。
I have a list of images that all have certain start and end dates for which they should be displayed on the page. 我有一张图像列表,所有图像都有特定的开始和结束日期,应该在页面上显示这些日期。 Before I continue, I am looking for a strictly Javascript/jQuery solution;
在继续之前,我正在寻找一个严格的Javascript / jQuery解决方案。 a server-side solution, however possible, is not what I'm asking for.
无论如何,服务器端解决方案都不是我要的。
I use a js example I found somewhere else to find the current date with the following: 我使用一个在其他地方找到的js示例,使用以下内容查找当前日期:
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var yearInt = parseInt(year);
var currentDate = month + "/" + day + "/" + year;
I then use ajax and $.each to go through all of my xml nodes and return all values, including a start date and end date for each image. 然后,我使用ajax和$ .each遍历所有xml节点并返回所有值,包括每个图像的开始日期和结束日期。
What type of conditional should I write so that the images display if they hold the following info: 我应该写什么类型的条件语句,以便在包含以下信息的情况下显示图像:
Current Date: 05/20/2010 当前日期:05/20/2010
Image1: Start Date: 01/30/2010 - End Date: 06/15/2010 图片1:开始日期:2010年1月30日-结束日期:2010年6月15日
Image2: Start Date: 05/20/2010 - End Date: 06/20/2010 图片2:开始日期:2010年5月20日-结束日期:2010年6月20日
Image2: Start Date: 06/12/2010 - End Date: 06/20/2011 图片2:开始日期:2010年6月12日-结束日期:2011年6月20日
And of course hide if they're past the end date? 当然,如果他们超过结束日期,就隐藏起来吗?
Any help would be greatly appreciated! 任何帮助将不胜感激! I'll answer any questions as quickly as possible.
我会尽快回答任何问题。 Thanks!
谢谢!
I would recommend casting your dates as Date()
objects, you can then do a comparison on them. 我建议将日期转换为
Date()
对象,然后可以对它们进行比较。
var currentDate = new Date(year, month, day);
var startDate = new Date(insert start date);
var endDate = new Date(insert end date);
if(currentDate >= startDate && currentDate < endDate) {
//show images
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.