[英]“Uncaught TypeError: object is not a function” Error in javascript
I am having a small problem. 我有一个小问题。 I want to display a slideshow, but the images are not moving.
我想显示幻灯片,但是图像没有移动。 When I check it in the console I get the error
当我在控制台中检查它时,我得到了错误
Uncaught TypeError: object is not a function
未捕获的TypeError:对象不是函数
Can someone please help me? 有人可以帮帮我吗?
Here's my javascript code: 这是我的JavaScript代码:
var step=1;
var images = [
"5c.jpg",
"5s.jpg",
"a65.jpg"
]; ]。
var slideshow = document.getElementById('slideshow'); var slideshow = document.getElementById('slideshow');
function slide(){
slideshow.src = images[step];
if(step<3){
step++;
}
else
step=1;
setTimeout("slide()",2500);
}
and my html file: 和我的html文件:
<html>
<body>
<img src="C:\Users\M.OAN\Desktop\Pics\Slideshow\5c.jpg" alt="images" name="slide" id="slideshow" onload="slide();"/>
</body>
</html>
You can make Array with your image paths and then just iterate thru it: 您可以使用图像路径创建Array,然后对其进行迭代:
HTML: HTML:
<img id="slideshow" src="http://placekitten.com/50/50" alt="images" name="slide"/>
JS: JS:
var images = [
"http://placekitten.com/100/100",
"http://placekitten.com/100/50",
"http://placekitten.com/50/100"
];
// get image element
var slideshow = document.getElementById('slideshow');
// in arrays index starts from 0
var step = 0;
setInterval(function(){
slideshow.src = images[step];
if( step < images.length-1 ){
step++;
} else {
step = 0;
}
}, 2500 );
Btw, I recommend you to use relative paths instead of absolute, because you may have problems when you try deploy your site: 顺便说一句,我建议您使用相对路径而不是绝对路径,因为在尝试部署站点时可能会遇到问题:
"Pics/Slideshow/5c.jpg"
instead of 代替
"C:/Users/M.OAN/Desktop/Pics/Slideshow/5c.jpg"
从一点儿麻烦来看,原始错误的根源是标签名称和功能相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.