рандомный блок
Есть 3 блока из разными id, нужно что бы при запуске страницы(обновлении)появля лся рандомный блок, помогите решить штуку.
|
<style>#one, #two, #three {display: none}</style> <script> document.write( '<style>#', ['one', 'two', 'three'][Math.floor(Math.random()*3)], '{display: block}</style>' ); </script> |
<style> #a1, #a2, #a3 { display: none; } </style> <div id="a1">a1</div> <div id="a2">a2</div> <div id="a3">a3</div> <script> document.addEventListener("DOMContentLoaded", () => { let rnd = ["a1", "a2", "a3"][Math.floor(Math.random()*3)]; document.getElementById(rnd).style.display = 'block'; }); </script> |
Ermite, зачем лишние перерисовки?
|
Часовой пояс GMT +3, время: 18:36. |