我在javascript中使用2個數組填充單詞,然後使用隨機化顯示每個數組中的1個單詞。但是,如果我想在第一個數組中選擇第二個單詞時播放標記爲「1.mp3」的特定聲音,並在第二個數組中選擇了第九個單詞時播放標記爲「8.mp3」的聲音。這些聲音會按照第一個數組聲音的順序播放,然後是第二個數組聲音。我正在使用cordova的Media插件來支持電話。任何人都可以指引我走向正確的方向嗎?根據隨機數組結果播放特定的聲音?
JavaScript的數組是這樣的:
var wordlist1 = ["Aggressive", "Amazing", "Attractive", "Black", "Broken", "Brave",
"Caring", "Cold", "Corny", "Delicious", "Dramatic", "Dull", "Euphoric", "Exotic",
"Evil", "Fabulous", "Feminine", "Fat", "Glorious", "Gripping", "Grand", "Hairy",
"Horny", "Hard", "Immense", "Idiotic", "Inferior", "Jam-Packed", "Juicy", "Jealous",
"Kooky", "Klutzy", "Knowledgeable", "Lame", "Lazy", "Loving", "Mad", "Milky", "Moist",
"Naive", "Naughty", "Neglected", "Oily", "Obese", "Overcooked", "Passionate", "Party",
"Peaceful", "Pasty", "Questionable", "Queasy", "Qualified", "Reckless", "Repulsive",
"Rubbery", "Slimy", "Salty", "Stiff", "Thick", "Terrible", "Thunderous", "Ugly",
"Uncomfortable", "Unpleasant", "Violent", "Vivid", "Vicious", "Wobbly", "Wee", "Wet",
"Young", "Yummy", "Yellowish", "Zany", "Zappy", "Zealous"]
var displayword1 = wordlist1[Math.floor(Math.random() * wordlist1.length)];
document.getElementById("word1").innerHTML = displayword1
第二陣列是幾乎相同的保存陣列&名 的內容,那麼我有一個HTML文件,將加載腳本;
<p id="word1"></p>
<script src="main.js"></script>
請問您能否添加一些描述您迄今所做工作的代碼? – Friederike 2014-10-02 13:50:48
我用一些代碼編輯了原文。 – MrBalrog 2014-10-02 13:55:01