我有一個小的腳本,在給定的時間段內通過數字遞增數字。如果增加一個值++的作品,如果我想添加math.random函數生成的另一個值而不是添加,請添加到現有值。我該如何改變這一點?我想要生成的數字添加到innerHTML中的現有值。添加數字,而不是增加增量
document.getElementById("data-gen").innerHTML = Math.floor((Math.random() * 100000) + 1) + Math.floor((Math.random() * 100) + 1);
nowResources = function() {
document.getElementById("data-gen").innerHTML += Math.floor((Math.random() * 10) + 1);
setTimeout(nowResources, 1000);
}
nowResources();
<span id="data-gen" style="color: #da5cb2;"></span>
[如何通過向元素添加整數值來更改innerHtml可能的重複?](https://stackoverflow.com/questions/17264978/how-to-change-innerhtml-by-adding-a-integer-value元素) – Andreas