Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript变量图像不是预期值_Javascript_Jquery_Html_Dom - Fatal编程技术网

JavaScript变量图像不是预期值

JavaScript变量图像不是预期值,javascript,jquery,html,dom,Javascript,Jquery,Html,Dom,我是HTML和JavaScript的完全初学者。我遇到了一个问题。我有一个按钮,在onclick下,我有: onclick="document.getElementById('slideCurrent').src=images[1]" var images = [ "PATH BLABLABLA_1", "PATH BLABLABLA_2", "PATH BLABLABLA_3" ]; 在JavaScript部分,我有: onclick="document.getEl

我是HTML和JavaScript的完全初学者。我遇到了一个问题。我有一个按钮,在
onclick
下,我有:

onclick="document.getElementById('slideCurrent').src=images[1]"
var images = [
    "PATH BLABLABLA_1",
    "PATH BLABLABLA_2",
    "PATH BLABLABLA_3"
];
在JavaScript部分,我有:

onclick="document.getElementById('slideCurrent').src=images[1]"
var images = [
    "PATH BLABLABLA_1",
    "PATH BLABLABLA_2",
    "PATH BLABLABLA_3"
];
由于某些原因,它不会显示图像。但是,如果我将路径直接放在那里,它将正常工作

我想要的是根据数组索引显示适当的图像。由于某种原因,控制台告诉我路径不正确:
加载资源失败:net::ERR\u文件未找到

下面是更完整的代码:

    <img id="slideCurrent" 
         src="file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE1.png"
         width="500"
         height="333"/>

    <input type="image"
           id="arrowCircularRight"
           src="file:///C:/Users/philip/Desktop/htmlCSA_files/arrowCircular_right.png"
           onclick="document.getElementById('slideCurrent').src=images[1]"
           width="50" 
           height="50"/>
    <script>
    var images = [
        "file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE1.png",
        "file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE2.png",
        "file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE3.png",
        "file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE4.png",
        "file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE5.png"
    ];

</script>

变量图像=[
"file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE1.png",
"file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE2.png",
"file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE3.png",
"file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE4.png",
"file:///C:/Users/philip/Desktop/htmlCSA_files/CSA_InfoGuide_TUTORIALSLIDE5.png"
];

问题在于变量名的选择。变量
images
与冲突。如果使用不同的变量名,它将起作用

下面是您的代码片段(稍加修改)。为了进行测试,我将图像URL更改为在堆栈溢出时有效的URL,并调整了

单击下面的图像以更改此行上方的图像(仅更改一次)

var myImages=[ "http://i.stack.imgur.com/jy5g5.png", "http://i.stack.imgur.com/S33VZ.png" ];
控制台中是否有错误?我在哪里可以找到控制台?请不要介意我的错误。控制台返回
加载资源失败:net::ERR_FILE_NOT_FOUND
,后跟
bla/bla/bla/undefined
Chrome。我使用了inspect元素并转到console选项卡。这意味着你的路径不正确,工作得很好!非常感谢您的帮助!:-)