[英]Changing the src of an img using (treeCut.src = “images/treeCut.png”;)
我的想法是將圖像從一棵完整的樹更改為一棵剪切樹,然后再轉換回完整的樹。 我的問題是,當我將其更改為剪切后的樹的圖片時,該圖像沒有顯示,但是當它切換回完整樹的圖像時,該顯示效果很好。 這是與問題有關的腳本:
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";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.