一段网上找的JS代码,运行时提示_this.container.childNodes[0].innerHTML为空或不是对象。。。

function nav(c, config){ this.config = config || {speed: 10, num: 2}; this.container = (typeof(c)=="object") ? c : document.getElementById(c); this.lineHeight = this.container.offsetHeight; this.scrollTimeId = null; var _this = this; this.__construct = function (){ var inner,el,href; inner = _this.container.childNodes[0].innerHTML; href = _this.container.childNodes[0].href; el = document.createElement("a"); el.innerHTML = inner; el.href = href; el.className = ✀hover✀; _this.container.appendChild(el); _this.container.onmouseover = function (){_this.start()}; _this.container.onmouseout = function (){_this.end()}; }(); this.start = function (){ _this.clear(); _this.scrollTimeId = setTimeout(function(){_this.scrollUp();}, _this.config.speed); }; this.end = function (){ _this.clear(); _this.scrollTimeId = setTimeout(function(){_this.scrollDown();}, _this.config.speed); }; this.scrollUp = function (){ var c = _this.container; if(c.scrollTop >= _this.lineHeight){c.scrollTop = _this.lineHeight;return;} c.scrollTop += _this.config.num; _this.scrollTimeId = setTimeout(function(){_this.scrollUp();}, _this.config.speed); }; this.scrollDown = function (){ var c = _this.container; if(c.scrollTop <= 0){c.scrollTop = 0;return;} c.scrollTop -= _this.config.num; _this.scrollTimeId = setTimeout(function(){_this.scrollDown();}, _this.config.speed); }; this.clear = function (){clearTimeout(_this.scrollTimeId)};}(function(){ var container = document.getElementById(✀nav✀); var el_li = container.getElementsByTagName(✀li✀); var arr = []; for( var i = 0; i < el_li.length; i++){ if(el_li[i].className == ✀on✀) continue; arr[i] = new nav(el_li[i], {speed: 10, num: 4}); }})();不太懂JS,求9~~html代码:<div id="nav"> <ul class="clear"> <li><a href="index.aspx">首页<⼀a><⼀li> <li><a href="about1.aspx">公司简介<⼀a><⼀li> <li><a href="news1.aspx">公司动态<⼀a><⼀li> <li><a href="wh1.aspx">企业文化<⼀a><⼀li> <li><a href="#">查询系统<⼀a><⼀li> <li><a href="message.aspx">在线留言<⼀a><⼀li> <li class="nobg"><⼀li> <⼀ul><script type="text⼀javascript" language="javascript" src="CSS⼀nav.js"><⼀script><⼀div>
2026年09月26日 06:16
有2个网友回答
网友(1):

for( var i = 0; i < el_li.length; i++){
这句改成
for( var i = 0; i < el_li.length-1; i++){
就可以了

网友(2):

缺少id 为C的html对象。
光引js没用,还要配合html页面