<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<audio id="myAudio" controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
您的浏览器不支持 audio 与元素。
</audio>
<p>点击按钮获取或者设置播放的音频音量。</p>
<button onclick="getVolume()" type="button">查看音量?</button>
<button onclick="setHalfVolume()" type="button">设置音量为 0.2</button>
<button onclick="setFullVolume()" type="button">设置音量为 1.0</button>
<script>
var x = document.getElementById("myAudio")
function getVolume(){
alert(x.volume)
}
function setHalfVolume(){
x.volume = 0.2
}
function setFullVolume(){
x.volume = 1.0
}
</script>
</body>
</html>
<audio src="" autoplay="autoplay" loop="loop" id="bgAudio"></audio>
document.getElementById("bgAudio").volume = 0.8
/*设置背景音乐的音量为80%*/