简体   繁体   English

“未捕获的TypeError:对象不是函数” javascript中的错误

[英]“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 );

Demo fiddle 演示小提琴

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.

相关问题 Javascript错误,未捕获TypeError属性&#39;$&#39;的对象[object Object]不是函数 - Javascript Error, Uncaught TypeError Property '$' of object [object Object] is not a function Javascript“未捕获的TypeError:对象不是函数” - Javascript “Uncaught TypeError: object is not a function” JavaScript中的“未捕获的TypeError:Object不是函数” - “uncaught TypeError: Object is not a function” in JavaScript Javascript:未捕获的TypeError:对象不是函数 - Javascript: Uncaught TypeError: object is not a function Javascript“未捕获的TypeError:对象不是函数” - Javascript “Uncaught TypeError: object is not a function” 未捕获的类型错误:forEach 不是 javascript 函数中的函数错误 - Uncaught TypeError: forEach is not a function error in javascript function JavaScript“未捕获的类型错误:object 不是函数”关联性问题 - JavaScript "Uncaught TypeError: object is not a function" associativity question 未捕获的TypeError:Object.values不是JavaScript函数 - Uncaught TypeError: Object.values is not a function JavaScript javascript OOP不工作:未捕获TypeError:对象不是函数 - javascript OOP not working: Uncaught TypeError: object is not a function Javascript:未定义的未捕获typeerror不是对象方法的函数 - Javascript: uncaught typeerror undefined is not a function for object methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM