为什么这段连续滚动的js在单独的页面可以
但放入程序中就不行了
红色代码部分在单独的页面有值
放入程序中就没有值了<script>var obj_marquee = document.getElementById("marquee");
var repeat = null;
var marquee_spd = <%=speed %>;
var marquee_dct = "<%=direction %>";function marquee_init() {
  var obj_unit = obj_marquee.firstChild;
  var marquee_high = parseInt(obj_marquee.style.height);
  var marquee_wide = parseInt(obj_marquee.style.width);
  var unit_high = obj_unit.offsetHeight;
  var unit_wide = obj_unit.offsetWidth;
  var m = 0, n = 0, i = 0;
  var tmp = null; 
 
  
  m = Math.ceil(marquee_wide / unit_wide);  
  n = Math.ceil(marquee_high / unit_high);  obj_unit.style.width = marquee_wide * (m+1);
  obj_unit.rows[0].cells[0].style.width = obj_marquee.style.width;
  
  if(marquee=="up" || marquee=="down" || marquee=="left" || marquee=="right" )  
  for(i=0; i<m; i++) {
    tmp = obj_unit.rows[0].insertCell(-1);
    tmp.innerHTML = obj_unit.rows[0].cells[0].innerHTML;
    tmp.style.width = marquee_wide;
    tmp = null;
  }  for(i=0; i<n; i++) {
    obj_marquee.appendChild(obj_unit.cloneNode(true));
  }
  return;
}function marquee_show(direction) {
  switch(direction) {
    case "up":
      if(obj_marquee.scrollTop >= obj_marquee.children[1].offsetTop) {
        obj_marquee.scrollTop -= obj_marquee.firstChild.offsetHeight;
      } else {
        obj_marquee.scrollTop++;
      }
      break;
    case "down":
      if(obj_marquee.scrollTop <= 0) {
        obj_marquee.scrollTop += obj_marquee.firstChild.offsetHeight;
      } else {
        obj_marquee.scrollTop--;
      }
      break;
    case "left":
      if(obj_marquee.scrollLeft >= obj_marquee.firstChild.rows[0].cells[0].offsetWidth) {
        obj_marquee.scrollLeft -= obj_marquee.firstChild.rows[0].cells[0].offsetWidth;
      } else {
        obj_marquee.scrollLeft++;
      }
      break;
    case "right":
      if(obj_marquee.scrollLeft <= 0) {
        obj_marquee.scrollLeft += obj_marquee.firstChild.rows[0].cells[0].offsetWidth;
      } else {
        obj_marquee.scrollLeft--;
      }
      break;
    default:
      break;
  }
  return;
}function marquee_doit() {
  var direction = marquee_dct;
  if(direction != null) marquee_show(direction);  
  return;
}
 if(marquee_dct!="")
    marquee_init();
 
 repeat = setInterval("marquee_doit()",marquee_spd); marquee.onmouseover = function() {clearInterval(repeat);}
 marquee.onmouseout = function() {repeat=setInterval("marquee_doit()",marquee_spd);}
</script>

解决方案 »

  1.   

    理解obj_marquee.firstChild的意思么?
      

  2.   

    对js不熟
    大虾能说说么
    最好将整段js给注释下
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title><script language="javascript" type="text/javascript">
    var words = "kennie,你会回来吗?";
    var len_show = 0;
    var len_hide = 0;
    var space = 0;
    var timeId = 0;
    var timeFunc = "showWords()";

    function showWords()
    {
    if(len_show < words.length)
    {
    len_show += 1;
    marquee.innerText = words.substring(0, len_show);
    timeId = setTimeout("showWords()", 200);
    timeFunc = "showWords()";
    }
    else
    {
    len_show = 0;
    timeId = setTimeout("move()", 200);
    timeFunc = "move()";
    }
    }

    function move()
    {
    if(marquee.offsetWidth < div1.clientWidth)
    {
    space += 1;
    var strSpace = "";
    for(var i=0; i<space;i++)
    {
    strSpace += " ";
    }
    marquee.innerText = words + strSpace;
    timeId = setTimeout("move()", 200);
    timeFunc = "move()";
    }
    else
    {
    div1.style.textAlign = "left";
    space = 0;
    timeId = setTimeout("hideWords()", 200);
    timeFunc = "hideWords()";
    }
    }

    function hideWords()
    {
    if(len_hide < words.length)
    {
    len_hide +=1;
    marquee.innerText = words.substring(len_hide, words.length);
    timeId = setTimeout("hideWords()", 200);
    timeFunc = "hideWords()";
    }
    else
    {
    div1.style.textAlign = "right";
    len_hide = 0;
    timeId = setTimeout("showWords()", 200);
    timeFunc = "showWords()";
    }
    }

    </script>
    </head><body onload="showWords()">
    <div id="div1" style="width:500px; height:50px; float:right; text-align:right;">
    <span id="marquee" onmouseover="clearTimeout(timeId)" onmouseout="setTimeout(timeFunc, 200)"></span>
    </div>
    </body>
    </html>