1 回答
TA贡献1796条经验 获得超4个赞
我刚刚在新文本之前添加了innerHTML,因此它会附加它
function gibberish() {
var randomsequence = '';
var followup = '';
function makeid(length) {
var output = '';
var letters = 'abcdefghijklmnopqrstuvwxyz';
var charactersLength = letters.length;
for ( var i = 0; i < length; i++ ) {
output += letters.charAt(Math.floor(Math.random() * charactersLength));
}
return output;
}
var monkeyoutput1 = '';
var stringoutput = monkeyoutput1 + makeid(Math.floor((Math.random() * 26) + 1)) ;
monkeyoutput1 = stringoutput;
document.getElementById("monkeybox").innerHTML = document.getElementById("monkeybox").innerHTML + monkeyoutput1;
//document.getElementById("monkeybox").innerHTML = makeid(Math.floor((Math.random() * 26) + 1)) ;
}
setInterval(gibberish, 1000);
<div>
<h1> text </h1><p id="monkeybox"> placeholder text</p>
</div>
添加回答
举报