我的想法是将图像从一棵完整的树更改为一棵剪切树,然后再转换回完整的树。我的问题是,当我将其更改为剪切后的树的图片时,该图像没有显示,但是当它切换回完整树的图像时,该显示效果很好。这是与问题有关的脚本:
var treeCut;
switch(randomEvent){
case 1:
//add a log
document.getElementById("treeActive").innerHTML = "inActive1";
treeSpawn=setTimeout(spawnTree,5000);
//below is the piece i'm having issues with
treeCut = document.getElementById("treeButton");
treeCut.src = function() {
treeCut.src = "images/treeCut.png";
}
break;
//not showing the full switch just the part that is being exicuted.
function spawnTree(){
document.getElementById("treeActive").innerHTML = "Active";
count = 0;
document.getElementById("message").innerHTML = "chop " + count;
clearInterval(treeSpawn);
//brings the tree back to original image
treeCut.src = "images/tree.png";
}
是否存在问题,因为第二张图像需要具有自己的标签?我已经检查,再次检查和三次检查图像是否在正确的位置并正确命名。
最佳答案
您可以直接设置图像的src
,例如,更改:
treeCut.src = function() {
treeCut.src = "images/treeCut.png";
}
至
treeCut.src = "images/treeCut.png";