脚本给出了未定义的错误
问题描述:
我有一个滑动评论块的脚本,你可以在https://www.medprodisposal.com上看到它。脚本给出了未定义的错误
问题是证言的名称给出了一个未定义的错误与显示客户名称。
下面是HTML:
<div id="container">
<h2><span>Testimonials</span></h2>
<div id="comment"></div>
</div>
<div id="test"></div>
这里是脚本;
//create and fill the array
var commt = [ ];
var name = [ ];
var i = 0;
commt[0] = '<blockquote class="quote"><p>0';
commt[1] = '<blockquote class="quote"><p>1';
commt[2] = '<blockquote class="quote"><p>2';
commt[3] = '<blockquote class="quote"><p>3';
name[0] = 'Lindsey P./Champaign, IL.</p>';
name[1] = 'Dr. San Jose/Hayward, California';
name[2] = 'Thomas H./Palos Heights, Illinois';
name[3] = 'Mary Beth/Niceville, FL';
//shows how many comments there are
var maxComments = 4;
//get empty elements
var comment = document.getElementById('comment');
//this section will create the inital comment shown
//creates a random number
var number = Math.floor(Math.random() * 4);
//adds the HTML to div
window.onload = comment.innerHTML = "<p>" + commt[number] + "</p>" +
"<h3 class='commentSliderH3'>" + name[number] + "</h3>";
//This rotates the comments
setInterval(function() { //same content as above
var number = Math.floor(Math.random() * maxComments);
comment.innerHTML = "<p>" + commt[number] + "</p>" +
"<h3 class='commentSliderH3'>" + name[number] + "</h3>";
}, 9031); // Runs the function every 9031ms
未定义的错误显示的名称。它在IE中正确显示,但不在Chrome或FF上显示。
此代码似乎工作正常。我已经在Firefox和Chrome上运行,并且按预期工作。 http://jsfiddle.net/dvancuyk/nwd7opem/ –