这是我的HTML:
<form name="imageForm">
<table border=3>
<tr>
<td>
<input onclick="displayImage();" type=button value="Display Random Image">
</td>
</tr>
<tr>
<td>
<script type="text/javascript" src="trinit5.js"></script>
</td>
</tr>
</table>
</form>
如何将此HTML代码链接到以下JavaScript文件?我想添加一个调用displayImage函数的onClick事件处理程序
var imagesArray = ["thumbs/lrgokublack.png", "thumbs/lrtrunks.png", "thumbs/lrgohan.png", "thumbs/lrmajinvegeta.png"];
function displayImage(){
var num = Math.floor(Math.random() * 5);
document.canvas.src = imagesArray[num];
}
答案 0 :(得分:3)
var imagesArray = ["thumbs/lrgokublack.png", "thumbs/lrtrunks.png", "thumbs/lrgohan.png", "thumbs/lrmajinvegeta.png"];
function displayImage() {
var num = Math.floor(Math.random() * imagesArray.length);
window.canvas.src = imagesArray[num];
}
&#13;
<input onclick="displayImage()" type=button value="Display Random Image">
<img id="canvas"></img>
&#13;