仅在一年中的某些时间运行j / s? [英] Running j/s only at certain times of the year?

查看:89
本文介绍了仅在一年中的某些时间运行j / s?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我们可以对.js文件做一个小小的补充,这样在某些时候它只能读取
这一年而忽略了其他人?这是一个

圣诞节促销。


我们希望它只在11月1日 - 1月10日,任何一年运行。


谢谢。


Mika

解决方案




最好的解决方案是使用服务器语言在HTML中有条件地包含JS

文件。


如果它'不可能,您可以使用以下JS代码来检查

日期:


var date = new Date(),m = date.getMonth ()+ 1;

if(m> = 11 ||(m == 1&& date.getDate()< = 10)){

// ...

}


Julien


11月21日上午10:55," ;米卡" < a ... @ anon.comwrote:


大家好


我们可以加入一小部分一个.js文件,这样它只会在一年中的某些时间读取并且在其他时间被忽略?这是一个

圣诞节促销。


我们希望它只在11月1日 - 1月10日,任何一年运行。


谢谢。


Mika


谢谢,计算的结果是什么你放在下面?


如果它更容易我们可以按月去,所以我们想要它说的是:


是月11月或12月?

不是吗? =停止脚本

是吗? =继续脚本...

....然后我们在这里有季节性的j / s代码。


任何人都可以提供确切的代码放在我们的.js文件的顶部是

启用这个吗?


谢谢。


Julien Royer < el ******* @ gmail.com写信息

新闻:ee *********************** *********** @ b32g2000 hsa.googlegroups.com ...





最好的解决方案是使用服务器语言在HTML中有条件地包含JS

文件。


如果不可能,那么你可以使用以下JS代码检查

日期:

var date = new Date(),m = date.getMonth()+ 1;

if(m> = 11 ||(m == 1&& date.getDate()< = 10)){

// ...

}


Julien


11月21日上午10:55,Mika < a ... @ anon.comwrote:


>大家好

我们可以为a添加一小部分。 js文件,这样它只会在一年中的某些时间被读取而在其他时间被忽略?这是
圣诞促销。

我们希望它只在11月1日 - 1月10日,任何一年运行。

谢谢。

Mika



Mika在2007年11月21日5:41发表以下内容AM:


谢谢,你在下面计算的结果是什么?



如果你不能解决这个问题,你可能不想和js

文件混在一起。
< blockquote class =post_quotes>
如果它更容易我们可以按月去,所以我们想要它说的是:


月份是11月还是12月?

不是吗? =停止脚本

是吗? =继续脚本...

...然后我们在这里有季节性的j / s代码。



这就是代码的作用。


任何人都可以提供准确的代码放在顶部我们的.js文件到

启用了吗?



人们可以做什么,人们会做什么是两件事。


请不要顶尖。如果你回复

到这篇文章,请不要引用我的签名。


-

Randy
机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/


Hi all

Is there a small addition we can make to a .js file, so that it will only be
read during certain times of the year and ignored at the others? It''s for a
Christmas promo.

We want it to run only from 1 Nov - 10 Jan, any year.

Thanks.

Mika

解决方案

Hi,

The best solution would be to use a server language to include the JS
file conditionally in the HTML.

If it''s not possible, you can use the following JS code to check the
date:

var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {
// ...
}

Julien

On Nov 21, 10:55 am, "Mika" <a...@anon.comwrote:

Hi all

Is there a small addition we can make to a .js file, so that it will only be
read during certain times of the year and ignored at the others? It''s for a
Christmas promo.

We want it to run only from 1 Nov - 10 Jan, any year.

Thanks.

Mika


Thanks, what is the result of the calculation you put below?

If it is easier we can just go by month, so what we want it to say is:

Is the month Nov or Dec?
No? = Stop script here
Yes? = Continue script...
....then we have our seasonal j/s code here.

Can anyone provide the exact code to place at the top of our .js file to
enable this?

Thanks.

"Julien Royer" <el*******@gmail.comwrote in message
news:ee**********************************@b32g2000 hsa.googlegroups.com...

Hi,

The best solution would be to use a server language to include the JS
file conditionally in the HTML.

If it''s not possible, you can use the following JS code to check the
date:

var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {
// ...
}

Julien

On Nov 21, 10:55 am, "Mika" <a...@anon.comwrote:

>Hi all

Is there a small addition we can make to a .js file, so that it will only
be
read during certain times of the year and ignored at the others? It''s
for a
Christmas promo.

We want it to run only from 1 Nov - 10 Jan, any year.

Thanks.

Mika



Mika said the following on 11/21/2007 5:41 AM:

Thanks, what is the result of the calculation you put below?

If you can''t figure that out, you might not want to be mucking with js
files.

If it is easier we can just go by month, so what we want it to say is:

Is the month Nov or Dec?
No? = Stop script here
Yes? = Continue script...
...then we have our seasonal j/s code here.

That is what the code does.

Can anyone provide the exact code to place at the top of our .js file to
enable this?

What people can do and what people will do are two different things.

Please don''t top-post. And please don''t quote my signature if you reply
to this post.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


这篇关于仅在一年中的某些时间运行j / s?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆