Javascript 2个Java脚本彼此不工作
我有两个Java脚本没有一起工作。它们都是分开工作的,但放在一起只有一个工作。我就是这么叫他们的Javascript 2个Java脚本彼此不工作,javascript,conflict,Javascript,Conflict,我有两个Java脚本没有一起工作。它们都是分开工作的,但放在一起只有一个工作。我就是这么叫他们的 window.onload = initImages; window.onload = countdown(year,month,day,hour,minute); 如果我把“window.onload=initImages;”放在“倒计时”之后,那么只有图像起作用,如果倒计时在图像之后保持这种状态,那么只有倒计时起作用 // JavaScript Document
window.onload = initImages;
window.onload = countdown(year,month,day,hour,minute);
如果我把“window.onload=initImages;”放在“倒计时”之后,那么只有图像起作用,如果倒计时在图像之后保持这种状态,那么只有倒计时起作用
// JavaScript Document
function initImages() {
for (var x = 0; x < document.images.length; x++)
{
document.images[x].onclick = povecana;
}
}
function povecana() {
dir = "images/" + this.id + ".jpg";
if (undefined != window.proz)
{
proz.style.opacity = 0.6;
}
proz = document.getElementById(this.id);
proz.style.opacity = 1;
slika = document.getElementById("odabranaSlika");
slika.style.display= "block";
slika.innerHTML='<img src='+ dir +' " width="100%" height="450px" />';
jabuke = document.getElementById("default");
jabuke.style.display= "none";
tekst = document.getElementById("tekstOdabrane");
tekst.style.display = "block";
if (this.id=="slika1")
tekst.innerHTML="Idared je američka sorta nastala 1935.";
else (this.id=="slika2")
tekst.innerHTML="Fuji je zasigurno jedna od atraktivnijih";
}
/*
Count down until any date script-
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
Modified by Robert M. Kuhnhenn, D.O.
on 5/30/2006 to count down to a specific date AND time,
on 10/20/2007 to a new format, and 1/10/2010 to include
time zone offset.
*/
/* Change the items noted in light blue below to create your countdown target date and announcement once the target date and time are reached. */
var current="Winter is here!";//-->enter what you want the script to display when the target date and time are reached, limit to 20 characters
var year=2013; //-->Enter the count down target date YEAR
var month=12; //-->Enter the count down target date MONTH
var day=21; //-->Enter the count down target date DAY
var hour=18; //-->Enter the count down target date HOUR (24 hour clock)
var minute=38; //-->Enter the count down target date MINUTE
var tz=+1; //-->Offset for your timezone in hours from UTC (see http://wwp.greenwichmeantime.com/index.htm to find the timezone offset for your location)
//--> DO NOT CHANGE THE CODE BELOW! <--
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countdown(yr,m,d,hr,min){
theyear=yr;themonth=m;theday=d;thehour=hr;theminute=min;
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 todaystring1=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
var todaystring=Date.parse(todaystring1)+(tz*1000*60*60);
var futurestring1=(montharray[m-1]+" "+d+", "+yr+" "+hr+":"+min);
var futurestring=Date.parse(futurestring1)-(today.getTimezoneOffset()*(1000*60));
var dd=futurestring-todaystring;
var dday=Math.floor(dd/(60*60*1000*24)*1);
var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
document.getElementById('count2').innerHTML=current;
document.getElementById('count2').style.display="inline";
document.getElementById('count2').style.width="390px";
document.getElementById('dday').style.display="none";
document.getElementById('dhour').style.display="none";
document.getElementById('dmin').style.display="none";
document.getElementById('dsec').style.display="none";
document.getElementById('days').style.display="none";
document.getElementById('hours').style.display="none";
document.getElementById('minutes').style.display="none";
document.getElementById('seconds').style.display="none";
document.getElementById('spacer1').style.display="none";
document.getElementById('spacer2').style.display="none";
return;
}
else {
document.getElementById('count2').style.display="none";
document.getElementById('dday').innerHTML=dday;
document.getElementById('dhour').innerHTML=dhour;
document.getElementById('dmin').innerHTML=dmin;
document.getElementById('dsec').innerHTML=dsec;
setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000);
}
}
//JavaScript文档
函数initImages(){
对于(var x=0;x输入达到目标日期和时间时希望脚本显示的内容,最多20个字符
风险值年份=2013年;//-->输入每年的倒计时目标日期
变量月份=12;//-->输入每月的倒计时目标日期
var日=21;//-->输入倒计时目标日期
var小时=18;//-->输入倒计时目标日期小时数(24小时制)
变量分钟=38;//-->输入倒计时目标日期分钟
var tz=+1;//-->以小时为单位的时区与UTC的偏移量(请参见http://wwp.greenwichmeantime.com/index.htm 查找您所在位置的时区偏移)
//-->不要更改下面的代码!
它们正在被覆盖。不能将两个值赋给一个变量
比如说,
x = 5;
x = 10;
当然,x
将是10
。嗯,你也一样:window.onload
类似于x
,数字类似于你的函数
window.onload = func1;
window.onload = func2;
在这种情况下,将始终调用func 2,因为在第2条语句之后,您已将onload处理程序从func1更改为func2
试一试
你能从第一个函数调用第二个函数吗?非常感谢!答案很快:D
window.onload = func1;
window.onload = func2;
window.onload = function(){
func1();
func2();
}