配列から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