解决
大家好我刚刚开始使用基本的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 :(得分:0)
尝试:
<input type="button" value="Reload Page" onClick="processNext();">
答案 1 :(得分:0)
首先,您应该将JavaScript文件包含在html文件的<head>
部分中:
<script type="text/javascript" src="gallery.js"></script>
然后你可以调用该文件中包含的任何函数:
<input type="button" value="Reload Page" onClick="processNext();">