Comment parcourir les balises span en utilisant la boucle for en HTML/JavaScript ?
P粉668113768
P粉668113768 2024-03-31 16:15:40
0
1
346

Comment compresser autant de balises span ? J'essaie de le rendre aussi petit que possible. Tout conseil serait utile, merci !

<header>
<a href="#" class="loo">cat <i class="fa-d fa-ct"></i></a>>
<div class="particle">
  <span style="--i:50;"></span>
  <span style="--i:21;"></span>
  <span style="--i:16;"></span>
  <span style="--i:18;"></span>
  <span style="--i:13;"></span>
  <span style="--i:22;"></span>
  <span style="--i:15;"></span>
  <span style="--i:24;"></span>
  <span style="--i:17;"></span>
  <span style="--i:28;"></span>
  <span style="--i:12;"></span>
  <span style="--i:26;"></span>
  <span style="--i:23;"></span>
  <span style="--i:13;"></span>
  <span style="--i:17;"></span>
  <span style="--i:11;"></span>
  <span style="--i:21;"></span>
  <span style="--i:16;"></span>
</div>
</div>

C'est pourquoi je veux l'obtenir. Chaque --i:Number crée une particule à un moment aléatoire.

P粉668113768
P粉668113768

répondre à tous(1)
P粉308783585

Si vous recherchez un moyen plus compact de générer du HTML, peut-être que ce qui suit vous aidera ?

const html=[...new Array(18)].map(_=>``).join("\n");
console.log(html); // can be commented out ...
document.querySelector(".particle").innerHTML=html;
cat
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!