我想從數組中保留Javascript上下文。有什麼辦法可以做到這一點?或者更優雅的方式?來自Javascript的innerHTML數組
例:
<html>
<script type="text/javascript">
var rand = Math.floor(Math.random() * 6) + 1;
var i = Math.floor(Math.random() * 6) + 1;
var arr = ["'There are ' + i + ' dogs in the yard.'","'The other day I saw ' + i + ' pigs that one lake.'","'I can't believe there were ' + i + ' birds in your yard the other day.'","'Why were there ' + i + ' cats in my front yard?'","'There are ' + i + ' rabbits in the yard.'","'There are ' + i + ' snakes in the yard.'"];
document.getElementById('fudge').innerHTML = arr[rand];
</script>
<body>
<div id='fudge'></div>
</body>
</html>
你正在試圖做的是什麼?在這種情況下,「背景」是什麼意思? –
我正在嘗試從數組中獲取JavaScript,並能夠在innerHTML中使用該代碼...或者提醒等等。 – Stephen