2 u012850897 u012850897 于 2013.11.18 11:42 提问

!DOCTYPE声明后JS代码无效怎么解决?

用!DOCTYPE声明后,部分的JS效果无效了怎么解决啊?
!DOCTYPE代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

JS代码:

colours=new Array('ff0000','00ff00','3366ff','ff00ff','ffa500','ffffff','fff000')
amount=colours.length;
YgetDelay=0,XgetDelay=0,Ydelay=0,Xdelay=0,ns=(document.layers)?1:0,step=0.2,currStep=0,my=0,mx=0;
if (ns){
for (i=0; i < amount; i++)
document.write('<LAYER NAME="nsstars'+i+'" BGCOLOR='+colours[i]+' CLIP="0,0,2,2"></LAYER>');
}
else{
document.write('<div id="ie" style="position:absolute;top:0;left:0;"><div style="position:relative">');
for (i=0; i < amount; i++)
document.write('<span id="iestars" style="position:absolute;top:0;left:0;width:2px;height:2px;background:'+colours[i]+';font-size:2px"></span>');
document.write('</div></div>');
}
if (ns){
window.captureEvents(Event.MOUSEMOVE);
function nMouse(evnt){                               
my=evnt.pageY;mx=evnt.pageX
}
window.onMouseMove=nMouse;
}
else{
function iMouse(){
my=event.y;mx=event.x;
}
document.onmousemove=iMouse
}
function stars(){
if (!ns)ie.style.top=document.body.scrollTop;
for (i=0; i < amount; i++)
 {
 var layer=(document.layers)?document.layers["nsstars"+i]:iestars[i].style; 
 layer.top= Ydelay+100*Math.sin((5*Math.sin((currStep-15.99)/10))+i*70)*Math.sin((currStep)/10)*Math.cos((currStep+i*25)/10); 
 layer.left=Xdelay+180*Math.cos((5*Math.sin((currStep-15.99)/10))+i*70)*Math.sin((currStep)/10)*Math.cos((currStep+i*25)/10);
 }
currStep+=step;
}

function delay(){
Ydelay = YgetDelay+=(my-YgetDelay)*1/20;
Xdelay = XgetDelay+=(mx-XgetDelay)*1/20;
stars();
setTimeout('delay()',10);
}
delay();

2个回答

franzhong
franzhong   2013.11.21 12:58

无效了报什么样的错误,未定义?
你的js用<script type="text/javascript"></script>
扩起来没有

xy1224657942
xy1224657942   2013.11.27 16:21

除了楼上说的用没用script标签包起来之外,你有写js文档就绪函数了吗$(document).ready();

Csdn user default icon
上传中...
上传图片
插入图片