获取2个脚本以在同一网页上运行 [英] Getting 2 scripts to run on the same webpage

查看:45
本文介绍了获取2个脚本以在同一网页上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个scipts,我试图在同一页面上运行。一个

是时间/日期脚本,另一个是倒计时脚本(即倒计时

天,小时,分钟直到给定日期)。它们都相互独立地工作,但是,当两者都在页面上时,活动时钟

不起作用。我假设这是因为一些变量是

相同???


有人可以帮忙吗?!?!

以下是2个脚本:

**活动时钟显示当前时间/日期信息**

<! - 开始

var dayarray = new Array(Sunday,Monday,Tuesday,Wednesday,Thu rsday,Friday,Saturday)

var montharray = new Array(January,February,March,April,May,June,July,August,September ;,十月,Novem ber,十二月)

函数getthedate(){

var mydate = new Date()

var year = mydate.getYear()

if(year< 1000)

year + = 1900

var day = mydate .getDay()

var month = mydate.getMonth()

var daym = mydate.getDate()

if(daym< 10)

daym =" 0" + daym

var hours = mydate.getHours()

var minutes = mydate.getMinutes()

var seconds = mydate.getSeconds()

var dn =" AM"

if(hours> = 12)

dn =" PM" ;

if(小时> 12){

小时=小时-12

}

{

d = new Date();

Time24H = new Date();

Time24H.setTime(d.getTime()+(d.getTimezoneOffset() * 60000)+

3600000);

InternetTime = Math.round((Time24H.getHours()* 60 + Time24H.getMinut es())

/ 1.44);

if(InternetTime< 10)InternetTime =''00''+ InternetTime;

else if(InternetTime< 100)InternetTime =''0''+ InternetTime;

}

if(hours == 0)

hours = 12

if(minutes< = 9)

minutes =" 0" +分钟

if(秒< = 9)

秒=" 0" +秒

//在此处更改字体大小

var cdate = dayarray [day] +"," + montharray [month] +" " + daym + QUOT; " +一年+" |

+小时+:+ +分钟+ " + DN + QUOT;

if(document.all)

document.all.clock.innerHTML = cdate

else if(document.getElementById)

document.getElementById(" clock")。innerHTML = cdate

else

document.write(cdate)

}

if(!document.all&&!document.getElementById)

getthedate()

function goforit(){

if(document.all || document.getElementById)

setInterval(" getthedate()",1000)

}

window.onload = goforit


//结束 - >

和第二个脚本 - ****倒计时直到给定日期** ***

函数setcountdown(他们,月,日){

yr = theyear; mo = themonth; da = theday

}


//////////在这里配置COUNTDOWN SCRIPT //////////////////


//步骤1:按年份,月份格式配置倒计时日期,

天:

setcountdown(2004,12,25) )


//步骤2:C感谢下面的两个文字以反映这个场合,并在那个场合分别显示
消息

var occasion =" Christmas!"

var message_on_occasion ="圣诞快乐!"


//步骤3:配置以下5个变量来设置宽度,高度,

背景倒计时区域的颜色和文字样式

var countdownwidth =''480px''

var countdownheight ='''20px''

var countdownbgcolor =''white''

var opentags =''< font face =" Arial"大小= QUOT; 4英寸color =" red">< small>''

var closetags =''< / small>< / font>''


//////////不要编辑通过这条线//////////////////


var montharray = new Array(Jan,Feb,Mar,Apr,May,Jun,Jul,A ug,Sep, ;十月,十一月,十二月)

var crosscount =''''

函数start_countdown(){

if(document.layers)

document.countdownnsmain.visibility =" show"

else if(document.all || document.getElementById)

crosscount = document.getElementById&&!document.all? document.getElementById(" countdownie")

:countdownie

倒计时()

}


if(document.all || document.getElementById)

document.write(''< span id =" countdownie"

style =" width:' '+ countdownwidth +'';

background-color:''countdownbgcolor +''">< / span>'')


窗口。 onload = start_countdown

函数倒计时(){

var today = new Date()

var todayy = today.getYear()

if(todayy< 1000)

todayy + = 1900

var todaym = today.getMonth()

var todayd = today.getDate()

var todayh = today.getHours()

var todaymin = today.getMinutes()

var todaysec = today。 getSeconds()

var todaystring = montharray [todaym] +" " + todayd +"," + todayy +"

" + todayh +":" + todaymin +":" + todaysec

futurestring = montharray [mo-1] +" " + da +"," + yr

dd = Date.parse(futurestring)-Date.parse(todaystring)

dday = Math.floor(dd /(60 * 60 * 1000 * 24)* 1)

dhour = Math.floor((dd%(60 * 60 * 1000 * 24))/(60 * 60 * 1000)* 1 )

dmin = Math.floor(((dd%(60 * 60 * 1000 * 24))%(60 * 60 * 1000))/(60 * 1000)* 1)
dsec = Math.floor((((dd%(60 * 60 * 1000 * 24))%(60 * 60 * 1000))%(60 * 1000))/ 1000 * 1)

//如果在某一天

if(dday< = 0&& dhour< = 0&& dmin< = 0&& dsec< = 1&& todayd == da){

if(document.layers){

document.countdownnsmain.document.countdownnssub.d ocument.write(opentags + message_on_occasion + closeta gs)

document.countdownnsmain.document.countdownnssub.d ocument.close()

}

else if(document.all || document.getElementById)

crosscount.innerHTML = opentags + message_on_occasion + closetags

返回

}

//如果通过日期

else if(dday< = - 1){

if(document.layers){

document.countdownnsmain.document.countdownnssub.d ocument.write(opentags +"场合

已经过去了! " + closetags)

document.countdownnsmain.document.countdownnssub.d ocument.close()

}

else if(document.all || document.getElementById)

crosscount.innerHTML = opentags +"场合已经过去了! + closetags

返回

}

//否则,如果还没有

else {

if(document.layers){

document.countdownnsmain.document.countdownnssub.d ocument.write(opentags + dday +

" days," + dhour +" hours," + dmin +" minutes," + dsec +" seconds left

直到" + occasion + closetags)

document.countdownnsmain.document.countdownnssub.d ocument.close()

}

else if(document.all || document.getElementById)

crosscount.innerHTML = opentags + dday +"天,+ dhour +小时,+ dmin +

分钟,以及+ dsec +几秒钟,直到+场合+ closetags

}

setTimeout(" countdown()",1000)

}

解决方案

" Mary Catherine" <马************* @ gmail.com>在消息中写道

news:58 ************************** @ posting.google.c om ...

我有2个scipts,我试图在同一页面上运行。一个是时间/日期脚本,另一个是倒计时脚本(即倒计时天,小时,分钟直到给定日期)。它们彼此独立工作,但是,当两者都在页面上时,活动时钟
不起作用。我假设是因为有些变量是相同的???




[snip]


montharray宣布两次。


var montharray = new

数组(1月,2月,3月,4月, May,June,July,August,Sep

tember,October,November,12月)


var montharray = new

Array(Jan,Feb,Mar,Apr,May, Jun,Jul,A ug,Sep,Oct,Nov,Dec



JRS:文章< hPMkd.86544


R05.20332@attbi_s53> ;,日期为11月11日星期四

2004 16:54:37,在新闻中看到:comp.lang.javascript,McKirahan

< Ne ** @ McKirahan.com>发布:

" Mary Catherine" <马************* @ gmail.com>在消息中写道
新闻:58 ************************** @ posting.google。 com ...

我有2个scipts,我试图在同一页面上运行。一个是时间/日期脚本,另一个是倒计时脚本(即倒计时天,小时,分钟直到给定日期)。它们彼此独立工作,但是,当两者都在页面上时,活动时钟
不起作用。我假设这是因为一些变量是相同的???



[snip]

montharray声明两次。

var montharray = new
数组(1月,2月,3月,4月,5月,6月 ;,July,August,Sep
tember,October,November,December)

var montharray = new <数组(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep, 十月,十一月,十二月,十二月,十二月,一行,十二月,一行,这是不可取的,但不会造成伤害。 >

OP'的代码没有缩进结构,因此不值得

完整阅读。但是: -


对于时钟,setTimeout(...,1000)是不合适的;请参阅

< URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>


var year = mydate.getYear(); if(year< 1000)year + = 1900

将在提供序列97,98,99,00,01的浏览器上失败;据说这是

存在。使用getFullYear或替代品:

< URL:http://www.merlyn.demon.co.uk/js-date0.htm#gFY>,getFY()。


InternetTime似乎是对中欧标准的估计

时间;但似乎没有使用。


倒计时不允许夏令时转换;用户将在b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 25 25 25 br />
例子。


-

?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 IE 4?

< URL:http://www.jibbering.com/faq/> JL / RC:新闻常见问题:comp.lang.javascript

< URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr数学,日期,来源。

< URL:http://www.merlyn.demon.co.uk/> TP / BP / Delphi / jscr /& c,常见问题项目,链接。


I have 2 scipts that I am trying to get to run on the same page. One
is a time/date script, the other is a countdown script (i.e. countdown
days, hours, mins until a given date). They both work independent of
each other, however, when both are on the page, the "active clock"
does not work. I am assuming it is because some of the variables are
the same???

Can anyone help please?!?!
Here are the 2 scripts:
**Active Clock that displays current time/date info**
<!-- Begin
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thu rsday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December")
function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
{
d = new Date();
Time24H = new Date();
Time24H.setTime(d.getTime() + (d.getTimezoneOffset()*60000) +
3600000);
InternetTime = Math.round((Time24H.getHours()*60+Time24H.getMinut es())
/ 1.44);
if (InternetTime < 10) InternetTime = ''00''+InternetTime;
else if (InternetTime < 100) InternetTime = ''0''+InternetTime;
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate=dayarray[day]+", "+montharray[month]+" "+daym+" "+year+" |
"+hours+":"+minutes+" "+dn+" "
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}
window.onload=goforit

// End -->
And the 2nd script - ****Countdown until given date*****
function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month,
day:
setcountdown(2004,12,25)

//STEP 2: Change the two text below to reflect the occasion, and
message to display on that occasion, respectively
var occasion="Christmas!"
var message_on_occasion="Merry Christmas!"

//STEP 3: Configure the below 5 variables to set the width, height,
background color, and text style of the countdown area
var countdownwidth=''480px''
var countdownheight=''20px''
var countdownbgcolor=''white''
var opentags=''<font face="Arial" size="4" color="red"><small>''
var closetags=''</small></font>''

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec")
var crosscount=''''

function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all? document.getElementById("countdownie")
: countdownie
countdown()
}

if (document.all||document.getElementById)
document.write(''<span id="countdownie"
style="width:''+countdownwidth+'';
background-color:''+countdownbgcolor+''"></span>'')

window.onload=start_countdown
function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+"
"+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000) )/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000 ))%(60*1000))/1000*1)
//if on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da ){
if (document.layers){
document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+message_on_occasion+closeta gs)
document.countdownnsmain.document.countdownnssub.d ocument.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+ closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+"Occasion
already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.d ocument.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+dday+
" days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left
until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.d ocument.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+"
minutes, and "+dsec+" seconds left until "+occasion+closetags
}
setTimeout("countdown()",1000)
}

解决方案

"Mary Catherine" <Ma*************@gmail.com> wrote in message
news:58**************************@posting.google.c om...

I have 2 scipts that I am trying to get to run on the same page. One
is a time/date script, the other is a countdown script (i.e. countdown
days, hours, mins until a given date). They both work independent of
each other, however, when both are on the page, the "active clock"
does not work. I am assuming it is because some of the variables are
the same???



[snip]

"montharray" is declared twice.

var montharray=new
Array("January","February","March","April","May"," June","July","August","Sep
tember","October","November","December")

var montharray=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec
")


JRS: In article <hPMkd.86544


R05.20332@attbi_s53>, dated Thu, 11 Nov
2004 16:54:37, seen in news:comp.lang.javascript, McKirahan
<Ne**@McKirahan.com> posted :

"Mary Catherine" <Ma*************@gmail.com> wrote in message
news:58**************************@posting.google. com...

I have 2 scipts that I am trying to get to run on the same page. One
is a time/date script, the other is a countdown script (i.e. countdown
days, hours, mins until a given date). They both work independent of
each other, however, when both are on the page, the "active clock"
does not work. I am assuming it is because some of the variables are
the same???



[snip]

"montharray" is declared twice.

var montharray=new
Array("January","February","March","April","May", "June","July","August","Sep
tember","October","November","December")

var montharray=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul"," Aug","Sep","Oct","Nov","Dec
")



That''s undesirable, but does no harm.

The OP''s code is not indented for structure, and therefore not worth
reading in full. However :-

For a clock, setTimeout(..., 1000) is unsuitable; see
<URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>

var year=mydate.getYear() ; if (year < 1000) year+=1900
will fail on browsers which give the sequence 97,98,99,00,01 ; such
were said to exist. Use getFullYear or a substitute :
<URL:http://www.merlyn.demon.co.uk/js-date0.htm#gFY>, getFY() .

InternetTime appears to be an estimate of Central European Standard
Time; but it seems not to be used.

The countdown will not allow for Summer Time transitions; users will
expect an integer number of days between 25 Jun 0000h and 25 Dec 0000h.

The programmer should have modularised the code, Leading Zero being an
example.

--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


这篇关于获取2个脚本以在同一网页上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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