my code is supposed to show a picture depending on witch pic it lands on in the random function.
this is my html
<div>
<h2>Joureur 0:</h2>
<div id="MainJoueur0"></div>
</div>
then in my .ts i did this
afficherCarteJoueurZero() {
document.getElementById('MainJoueur0').innerHTML = '<div></div>';
for (let i = 0; i < 2; i++) {
let img = new Image(90, 130);
img.src = "assets/images/" + this.sorte + "_" + this.valeur + ".gif";
document.getElementById('MainJoueur0').appendChild(img);
}
}
img.src = "assets/images/" + this.sorte + "_" + this.valeur + ".gif";
this.sorte 和 this.valeur 是数组,你不应该从中选择一个索引吗?
The sorte and valeur is array
, you need get string by index
as
for (let i = 0; i < 2; i++) { let img = new Image(90, 130); img.src = "assets/images/" + this.sorte[i] + "_" + this.valeur[i] + ".gif"; document.getElementById('MainJoueur0').appendChild(img); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.