我正在尝试将随机单词输出到特定的html元素中。我快到了-但是我想我把打印文本的部分弄乱了...谁能给我有关我要去哪里错的提示?var txtGreeting = 10;var randomCount = Math.round(Math.random() * (txtGreeting - 1)) + 1;var greeting = new Array();greeting[1] = "hello",greeting[2] = "ciao",greeting[3] = "welcome",greeting[4] = "howdy",greeting[5] = "greetings",greeting[6] = "salut",greeting[7] = "hallo",greeting[8] = "hola",greeting[9] = "Gday",greeting[10] = "Hey",document.getElementById("title").html = "greeting[randomCount]"; 最佳答案 我将为您整理代码。您写的是一次伟大的尝试!var greetings = [ "hello" , "ciao" , "welcome" , "howdy" , "greetings" , "salut" , "hallo" , "hola" , "Gday" , "Hey"];var greeting_id = Math.floor(Math.random() * greetings.length);document.getElementById('title').innerHTML = greetings[greeting_id];它使用数组文字,一个“适当的”基于零的数组(使选择随机索引更加容易),动态的.length属性,因此您不必仅因为要添加新的问候而重写代码,最后,而不只是.innerHTML。 08-08 07:24