0
嗨,大家我試圖做一個隨機生成的Discourses,但我不想刷新整個頁面以獲得一個新的字符串,所以我想也許innerHTML可能是我的解決方案。不幸的是,當我點擊按鈕時,結果爲「UNDEFINED」。我不知道如何繼續。提前致謝。undefined innerHTML(當試圖刷新時)
<span id="generator" style="font-size: 20px; font-weight: bold;">
<script language="javascript" type="text/javascript">
Words1 = new Array("blablabla1","blablabla2")
Words2 = new Array("blablabla3","blablabla4")
var random = document.write('- ' +
Words1[Math.floor((Math.random() * 100000) % Words1.length)] +
' ' +
Words2[Math.floor((Math.random() * 100000) % Words2.length)] +
'.\n');
function refresh(){
document.getElementById('generator').innerHTML = random;
}
</script>
</span>
<input type='button' onclick='refresh()' value='refresh'/>