国货彩妆:求JS控制bgsound的方法

来源:百度文库 编辑:中科新闻网 时间:2024/04/19 22:54:04
在网页里可以用<bgsound src=....>来实现声音的插入.
假如我想用Javascript代码来实现声音的控制该如何写.
(具体做法为:做一个下拉菜单,可以自行选择背景音乐)
谢谢你们,哪位大侠有时间的可以帮我写更多,如(如何JS控制音量:)~!!!)
谢谢你的答案,我把你的静音控制改了一下.希望能够在二次点击时恢复声音.但是不能生效.麻烦你帮我看一下好吗?
Function btnSilence_OnClick()
Dim iVolume
If iVolume>-10000 Then
document.all.oSound.volume = -10000
Else
document.all.oSound.volume = 0
End If
End Function

地址可以通过修改它的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
这样才能进行比较。