如何把这段代码放到js文件里引用?
如何把这段代码放到js文件里引用?
用window.onload会报错。说是找不到area,
window.onload = function(){ var area = document.getElementById('moocbox'); var con1 = document.getElementById('con1'); var con2 =document.getElementById('con2'); con2.innerHTML = con1.innerHTML; function scrollUp(){ if(area.scrollTop >= con1.offsetHeight){ area.scrollTop = 0; }else{ area.scrollTop++; } } var timer = 50; var myScroll = setInterval('scrollUp()',timer); area.onmouseover = function(){ clearInterval(myScroll); } area.onmouseout = function(){ myScroll = setInterval('scrollUp()',timer); } }