JQuery音乐阵列

时间:2017-12-13 23:44:52

标签: jquery keycode

如何获取第一行代码并将其放入类似var sound的数组中。

var audio1 = new Audio("assets/sounds/steelsword.mp3");
var sounds = Audio[
    "assets/sounds/steelsword.mp3",
    "assets/sounds/sword1.mp3",
    "assets/sounds/swordecho.mp3",
    "assets/sounds/swordraw.mp3",
    "assets/sounds/wv_sword.mp3"
]

2 个答案:

答案 0 :(得分:1)

            <div class="contact-bottom"> 
            <div class="col-md-6 contact-left"> 
            <form>
                <input type="text" placeholder="Name" required="">
                <input type="text" placeholder="E-mail" required="">
                <input type="text" placeholder="Phone" required="">
            </form>
            </div>
            <div class="col-md-6 contact-left">
            <form>
                <textarea placeholder="Message"></textarea>
                <input type="submit" value="SEND">
            </form> 
            </div>
            <div class="clearfix"> </div>
        </div>

答案 1 :(得分:1)

在原始JavaScript中,您只需使用 array.push()

&#13;
&#13;
var sounds = ["assets/sounds/steelsword.mp3", "assets/sounds/sword1.mp3", "assets/sounds/swordecho.mp3", "assets/sounds/swordraw.mp3", "assets/sounds/wv_sword.mp3"];
sounds.push("assets/sounds/steelsword.mp3");
console.log(sounds);
&#13;
&#13;
&#13;

然后只需从阵列中选择要加载的音频文件,调用 new Audio() ,然后设置音频 src attribute

&#13;
&#13;
var sounds = ["assets/sounds/steelsword.mp3", "assets/sounds/sword1.mp3", "assets/sounds/swordecho.mp3", "assets/sounds/swordraw.mp3", "assets/sounds/wv_sword.mp3"];
sounds.push("assets/sounds/steelsword.mp3");

var audio = new Audio();
audio.src = sounds[5];
&#13;
&#13;
&#13;