计划内容的JavaScript代码
我想在我的网站上安排一个特定日期的内容,此代码有效,但它只在10、11和12个月显示内容,其余的1-9个月不显示。我想每个月显示。。。请帮帮我计划内容的JavaScript代码,javascript,Javascript,我想在我的网站上安排一个特定日期的内容,此代码有效,但它只在10、11和12个月显示内容,其余的1-9个月不显示。我想每个月显示。。。请帮帮我 function autogoLive() { var goLiveMonth = "10" // Month you want your content to start displaying. Two digits. var goLiveDay = "20" // Day you want your content to start
function autogoLive() {
var goLiveMonth = "10" // Month you want your content to start displaying. Two digits.
var goLiveDay = "20" // Day you want your content to start displaying. Two digits.
var goLiveYear = "2015" // Year you want your content to start displaying. Four digits.
/* This is where you put your content. Make sure you escape any quotation marks with a backslash. Make sure you do not delete the opening and closing quotes. */
var myContent = "This text will display, <strong>beginning and ending</strong> on the dates you have set."
/* Don't edit below this line. Don */
var goLiveDate = goLiveYear + goLiveMonth + goLiveDay; // puts START year, month, and day together.
var nowDate = new Date();
var day = nowDate.getUTCDate();
var month = nowDate.getUTCMonth();
var correctedMonth = month + 1; //month - JavaScript starts at "0" for January, so we add "1"
if (correctedMonth < 10) { /* if less than "10", put a "0" in front of the number. */
correctedMonth = "0" + correctedMonth;
}
if (day < 10) { /* if less than "10", put a "0" in front of the number. */
day = "0" + day;
}
var year = nowDate.getYear(); /* Get the year. Firefox and Netscape might use century bit, and two-digit year. */
if (year < 1900) {
year = year + 1900; /*This is to make sure Netscape AND FireFox doesn't show the year as "107" for "2007." */
}
var GMTdate = year + "" + correctedMonth + "" + day; //corrected month GMT date.
if ((GMTdate >= goLiveDate)) {
document.write(myContent)
}
}
function autogoLive(){
var goLiveMonth=“10”//您希望您的内容开始显示的月份。两位数。
var goLiveDay=“20”//您希望您的内容开始显示的日期。两位数。
var goLiveYear=“2015”//您希望内容开始显示的年份。四位数字。
/*这是您放置内容的地方。请确保用反斜杠转义任何引号。确保不删除开始引号和结束引号*/
var myContent=“此文本将在您设置的日期显示开始和结束时间。”
/*不要在这行下面编辑。不要*/
var goLiveDate=goLiveYear+goLiveMonth+goLiveDay;//将开始年份、月份和日期放在一起。
var nowDate=新日期();
var day=nowDate.getUTCDate();
var month=nowDate.getUTCMonth();
var correctedMonth=month+1;//month-JavaScript从1月份的“0”开始,因此我们添加了“1”
如果(校正月数<10){/*如果小于“10”,请在数字前加上“0”*/
更正的月份=“0”+更正的月份;
}
如果(天<10){/*如果小于“10”,请在数字前加一个“0”*/
day=“0”+天;
}
var year=nowDate.getYear();/*获取年份。Firefox和Netscape可能使用世纪位和两位数年份*/
如果(年份<1900年){
year=year+1900;/*这是为了确保Netscape和FireFox不会将年份显示为“2007”的“107”*/
}
var GMTdate=year+“”+correctedMonth+“”+day;//correctedMonth GMT日期。
如果((GMTdate>=goLiveDate)){
文件编写(myContent)
}
}
我会比较日期对象,而不是字符串对象
Var showDate=new Date("January 1, 2016"); // date you want the content to appear
Var today =new Date();
if(today>=showDate){
//function to show your content
}
可以找到有关如何使用日期对象的更多信息
上述代码的问题在于它比较的是字符串,而不是数字或日期,因此它们并不总是以您预期的方式显示为大于或小于
我已经附加了一些功能代码,它确实使用jquery,但我相信您可以使用通用表单
$(文档).ready(函数(){
var showDate=新日期('2015年11月22日16:05:00');
var today=新日期();
如果(今天>=showDate){
$('div').append('p>helloworld');
}
});代码>
旁注:已被弃用,取而代之的是,这将为您提供2015
而不是115
“我想每月显示”您能进一步解释一下吗?是否要删除日期作为条件?或者,在每个月的特定日期显示内容?此代码不起作用。您能帮我吗?