嗨,我想創建一個JavaScript演示文稿我正在努力的網站。這是非常基本的,主要是使用w3schools的指南之一。當我在內部使用JavaScript時,演示文稿正常工作,但是在外部使用它時,它會將所有圖片加載到列表中,但是當您按下「下一步」按鈕時,它們全部消失並且演示文稿正常工作。 here is the page on load我的外部javascript不能正常工作,但內部它很好
下面是HTML
<script type="text/javascript" src="../javascript/slide.js"></script>
<div class="slideshowcontainer">
<img class="slideshow" src="../images/formalplace1.jpg" style="width:500px" "height:400px">
<img class="slideshow" src="../images/formalplace2.jpg" style="width:500px" "height:400px">
<img class="slideshow" src="../images/formalplace3.jpg" style="width:500px" "height:400px">
<img class="slideshow" src="../images/formalplace4.jpg" style="width:500px" "height:400px">
<button class="left-button" onclick="plusDivs(-1)">❮</button>
<button class="right-button" onclick="plusDivs(1)">❯</button>
</div>
和JavaScript
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("slideshow");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
我不是很熟悉JavaScript,但是我已經嘗試在做的window.onload和document.onload也是周邊它與功能。
任何幫助將不勝感激,謝謝。
確保你的外部腳本要麼裝在''
標籤的結束或有'defer'屬性。 – gyre你把你的劇本放在哪裏? –
你能告訴我們你是如何加載你的外部javascript文件的嗎? –