解決済み
こんにちは皆さん、私は基本的な 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>