为什么js部分放在head里的话就报错,放在body里就可以?
<script>
window.onload=function(){
var con1=document.getElementById("con1");
var con2=document.getElementById("con2");
var are=document.getElementById("big");
var speed = 50;
are.scrollTop = 0;
con2.innerHTML = con1.innerHTML;
function scrollUp(){
if(are.scrollTop >= con1.scrollHeight) {
are.scrollTop = 0;
}else{
are.scrollTop ++;
}
}
var myScroll = setInterval("scrollUp()",speed);
are.onmouseover = function(){
clearInterval(myScroll);
}
are.onmouseout = function(){
myScroll = setInterval("scrollUp()",speed);
}
</script>
这是放在head里的代码,显示scrollUp未定义。
另外,在head中用window.onload和js放在body最后有什么具体区别?