2012-10-10 55 views
1

解决Reload按钮,不能使它工作

好家伙,我刚开始学习基本的JavaScript和只是想知道我怎么可以从按钮的同时调用这个函数保持所有的代码里面gallery.js

<input type="button" value="Reload Page" onClick="window.location.reload()"> 

gallery.js文件

var slideShow = new Array(); 
slideShow[0]="images/1.jpg"; 
slideShow[1]="images/2.jpg"; 
slideShow[2]="images/3.jpg"; 
slideShow[3]="images/4.jpg"; 
slideShow[4]="images/5.jpg";//loads pictures 
slideShow[5]="images/6.jpg"; 
var thisPic = 0; 

function reloadURL() 
{ 
    window.location.reload(); 
} 

function processNext() { 
    if (document.images && thisPic < 5) { //process checks if this pic is less than 2 
     thisPic++; 
     document.getElementById("picture").src=slideShow[thisPic]; 
    else if(window.location.reload() 
    } 
} 
window.onload = init; //initially loads 

function init() { 
document.getElementById("next").onclick=processNext; //on button click next picture  is shown 


} 

gallery.html

<div id="content"> 
<h2>Gallery</h2> 
    <p>This is the gallery</p> 
    <img src="images/1.jpg" id="picture" alt="displays a slide show of 5 pictures"/><br/> 
    <input type="button" value="Press this button for next picture" id="next" /> 
    <input type="button" value="Reload" onclick="reloadURL();" /> 

</div> 

回答

0

尝试: <input type="button" value="Reload Page" onClick="processNext();">

0

首先,你应该在你的HTML文件的<head>部分JavaScript文件:

<script type="text/javascript" src="gallery.js"></script> 

然后就可以调用包含在该文件中的所有功能:

<input type="button" value="Reload Page" onClick="processNext();"> 
+0

仍然没有真正为我工作。我已经在头部输入了 bigols

+0

在Firefox或Chrome中按F12,选择“Net”或“Network”并查看右下角如果它显示任何错误..? – chr

+0

http://jsfiddle.net/bigol/rWWrG/ js控制台中没有错误 – bigols