function changeValue(){ const div = document.getElementById('value') var rand = '' for(var i=0;i<8;i++){ rand += Math.floor(Math.random()*10) } div.innerText = rand }
<div id="value"></div> <button onclick="changeValue()">改变</button>