| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 833 人关注过本帖
标题:关于在html中插入多个javascript标签出现冲突的问题
只看楼主 加入收藏
tkggddd
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-5-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
关于在html中插入多个javascript标签出现冲突的问题
关于在html中插入多个javascript标签出现冲突的问题。

我想在html中插入2个或更多的javascript标签,代码如下:

第一个:

<body onLoad="chgCol(); pingpong();">
<script language="JavaScript">
<!-- Hide from JavaScript-Impaired Browsers
var pos = 10;
function initArray() {
 this.length = initArray.arguments.length;
 for (var i = 0; i < this.length; i++) {
  this[i] = initArray.arguments[i];
  }
}
var col=new initArray("4b","5b","8b","8b");
col[0] = "white";
col[1] = "coral";
col[2] = "orange";
col[3] = "red";
col[4] = "greenyellow";
col[5] = "lime";
col[6] = "turquoise";
col[7] = "coral";
col[8] = "blueviolet";
col[9] = "violet";

function chgCol() {
  pos++;
  if (pos<0||pos>9) {
    pos = 0;
    }
  document.bgColor = col[pos];
  setTimeout("chgCol()",5000);
 }

var yourwords = "";var buffer1="           ";
var buffer2="           ";
var message1=buffer1+yourwords+buffer2;
var dir = "left";var speed =150;
function pingpong(){if (dir == "left")
 {    message2=message1.substring(2,message1.length)+"  ";
   window.status=message2;  
  setTimeout("pingpong();",speed);
   message1=message2;
   if (message1.substring(0,1) == "*") dir="right";
  }
else
 {    message2="  "+message1.substring(0,message1.length-2);
   window.status=message2;   
 setTimeout("pingpong();",speed);
   message1=message2;
   if (message1.substring(message1.length-1,message1.length) == "*") dir="left";
 }
}
// -->
</script>

 

 

第2个

<SCRIPT language=JavaScript>                     
<!--                     
dCol="0000FF"
fCol="FF0000"
sCol="00FF00"
mCol="000000"
hCol="000000"
ClockHeight=40;                     
ClockWidth=40;                     
ClockFromMouseY=0;                     
ClockFromMouseX=100;                     
                     
d=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");                     
m=new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");                     
date=new Date();                     
day=date.getDate();                     
year=date.getYear();                     
if (year < 2000) year=year+1900;                     
TodaysDate="年 "+m[date.getMonth()]+" "+day+"日 "+d[date.getDay()]+" "+year;                     
D=TodaysDate.split('');                     
H='...';                     
H=H.split('');                     
M='....';                     
M=M.split('');                     
S='.....';                     
S=S.split('');                     
Face='1 2 3 4 5 6 7 8 9 10 11 12';                     
font='Arial';                     
size=1;                     
speed=0.6;                     
ns=(document.layers);                     
ie=(document.all);                     
Face=Face.split(' ');                     
n=Face.length;                     
a=size*10;                     
ymouse=0;                     
xmouse=0;                     
scrll=0;                     
props="<font face="+font+" size="+size+" color="+fCol+">";                     
props2="<font face="+font+" size="+size+" color="+dCol+">";                     
Split=360/n;                     
Dsplit=360/D.length;                     
HandHeight=ClockHeight/4.5                     
HandWidth=ClockWidth/4.5                     
HandY=-7;                     
HandX=-2.5;                     
scrll=0;                     
step=0.06;                     
currStep=0;                     
y=new Array();x=new Array();Y=new Array();X=new Array();                     
for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0}                     
Dy=new Array();Dx=new Array();DY=new Array();DX=new Array();                     
for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0}                     
if (ns){                     
for (i=0; i < D.length; i++)                     
document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>');                     
for (i=0; i < n; i++)                     
document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>');                     
for (i=0; i < S.length; i++)                     
document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></layer>');                     
for (i=0; i < M.length; i++)                     
document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M[i]+'</b></center></font></layer>');                     
for (i=0; i < H.length; i++)                     
document.write('<layer name=nsHours'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center><b>'+H[i]+'</b></center></font></layer>');                     
}                     
if (ie){                     
document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');                     
for (i=0; i < D.length; i++)                     
document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</font></div>');                     
document.write('</div></div>');                     
document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');                     
for (i=0; i < n; i++)                     
document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</font></div>');                     
document.write('</div></div>');                     
document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');                     
for (i=0; i < H.length; i++)                     
document.write('<div id="ieHours" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>');                     
document.write('</div></div>');                     
document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');                     
for (i=0; i < M.length; i++)                     
document.write('<div id="ieMinutes" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>');                     
document.write('</div></div>')                     
document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');                     
for (i=0; i < S.length; i++)                     
document.write('<div id="ieSeconds" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>');                     
document.write('</div></div>')                     
}                     
(ns)?window.captureEvents(Event.MOUSEMOVE):0;                     
function Mouse(evnt){                     
ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;                     
xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX;                     
}                     
(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;                     
function ClockAndAssign(){                     
time = new Date ();                     
secs = time.getSeconds();                     
sec = -1.57 + Math.PI * secs/30;                     
mins = time.getMinutes();                     
min = -1.57 + Math.PI * mins/30;                     
hr = time.getHours();                     
hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;                     
if (ie){                     
Od.style.top=window.document.body.scrollTop;                     
Of.style.top=window.document.body.scrollTop;                     
Oh.style.top=window.document.body.scrollTop;                     
Om.style.top=window.document.body.scrollTop;                     
Os.style.top=window.document.body.scrollTop;                     
}                     
for (i=0; i < n; i++){                     
var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style;                     
F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;                     
F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);                     
}                     
for (i=0; i < H.length; i++){                     
var HL=(ns)?document.layers['nsHours'+i]:ieHours[i].style;                     
HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;                     
HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs);                     
}                     
for (i=0; i < M.length; i++){                     
var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes[i].style;                     
ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll;                     
ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min);                     
}                     
for (i=0; i < S.length; i++){                     
var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds[i].style;                     
SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll;                     
SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec);                     
}                     
for (i=0; i < D.length; i++){                     
var DL=(ns)?document.layers['nsDate'+i]:ieDate[i].style;                     
DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;                     
DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);                     
}                     
currStep-=step;                     
}                     
function Delay(){                     
scrll=(ns)?window.pageYOffset:0;                     
Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);                     
Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);                     
for (i=1; i < D.length; i++){                     
Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed);                     
Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed);                     
}                     
y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);                     
x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);                     
for (i=1; i < n; i++){                     
y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);                     
x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);                     
}                     
ClockAndAssign();                     
setTimeout('Delay()',40);                     
}                     
if (ns||ie)window.onload=Delay;                     
//-->                     
</SCRIPT>

我想把这2个javascript特效一起用,我直接写在一起后发生了冲突,请问是怎么回事?需要怎么修改2个特效才能都显示正常?
搜索更多相关主题的帖子: javascript html 
2010-05-24 22:23
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
收藏
得分:20 
我本机测试过了,一切正常没有冲突!
如你有加其他HTML标签,请记得变量名不要冲突,否则就有可能会出错!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2010-05-25 11:00
快速回复:关于在html中插入多个javascript标签出现冲突的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014936 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved