HTML背景声音文件的简单播放

第一,你只需要这么做:

 

function play(file) {
    var embed = document.createElement("embed");
    embed.setAttribute('src', file);
    embed.setAttribute('hidden', true);
    embed.setAttribute('autostart', true);
    document.body.appendChild(embed);
}

 

第二,完成调用

如, 

 play("song.wav");   play("song.mp3");....................

仅此而已。

原文地址:https://www.cnblogs.com/boonya/p/3027608.html