本文目錄一覽:
javascript 有音量函數嗎
volume屬性控制
!DOCTYPE html
html
head
meta charset=”utf-8″
titlea/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
如何調小網頁聲音?
方法:
找到網頁左下角的喇叭形狀的圖標;
有機鼠標;
出現高級設置,在高級設置中有調節網頁聲音的大小。
關閉和開啟網頁聲音直接點擊喇叭即可。
求JS控制bgsound的方法
地址可以通過修改它的src屬性來改變,音量可以使用它的volume 來改變,它的範圍為-10000到0。
舉一下改變聲音的例子吧。
SCRIPT Language=”VBScript”
Function btnUp_OnClick()
Dim iVolume
iVolume = document.all.oSound.volume + 500
If iVolume 0 Then
document.all.oSound.volume = iVolume
End If
End Function
Function btnDown_OnClick()
Dim iVolume
iVolume = document.all.oSound.volume – 500
If iVolume -10000 Then
document.all.oSound.volume = iVolume
End If
End Function
Function btnSilence_OnClick()
document.all.oSound.volume = -10000
End Function
/SCRIPT
bgSound src=”音樂地址” id=”oSound”/
button name=”btnUp”加大/button
button name=”btnDown”減小/button
button name=”btnSilence”靜音/button
———————————————
你定義了一個變量,但沒有賦值,所以不行,你需要對它進行賦值,如:
Dim iVolume
iVolume = document.all.oSound.volume
這樣才能進行比較。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/289017.html