页面加载html后播放音频 [英] Playing audio after the page loads in html
本文介绍了页面加载html后播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在html中插入了音频.但是音频会在整个页面加载之前开始.我希望在加载整个页面后播放音频.
I inserted the audio in html. But the audio gets started before the entire page loads. I want the audio to be played after the entire page gets loaded.
<audio src="bg.mp3" autoplay="autoplay" loop="loop"></audio>
有人可以帮我吗
推荐答案
您将需要JavaScript.删除autoplay
属性:
You're going to need JavaScript for that. Remove the autoplay
attribute:
<audio id="my_audio" src="bg.mp3" loop="loop"></audio>
并添加如下脚本:
window.onload = function() {
document.getElementById("my_audio").play();
}
或者,如果您使用jQuery:
Or if you use jQuery:
$(document).ready(function() {
$("#my_audio").get(0).play();
});
这篇关于页面加载html后播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文