1.控制播放和暂停
1
2
3
|
<
embed
id
=
"soundControl"
src
=
"文件路径及文件"
mastersound
hidden
=
"true"
loop
=
"false"
autostart
=
"false"
></
embed
>
<
input
id
=
"btPlay"
type
=
"button"
value
=
"播放"
onclick
=
"ManageSoundControl('play')"
/>
<
input
id
=
"btStop"
type
=
"button"
value
=
"停止"
onclick
=
"ManageSoundControl('stop')"
/>
|
1
2
3
4
5
6
7
8
9
10
11
12
|
function
ManageSoundControl(action)
{
var
soundControl = document.getElementById(
"soundControl"
);
if
(action ==
"play"
)
{
soundControl.play();
}
if
(action ==
"stop"
)
{
soundControl.stop();
}
}
|
2.JS隐式播放方式:(附带检测)(LOOP代表循环意思)
在页面body里加上
1
2
|
<bgsound id=
"snd"
loop=
"0"
src=
""
>
<input type=
"button"
value=
"声音"
onclick=
"playSound('这里填写你的声音文件路径')"
>
|
在<head></head>之间加上
1
2
3
4
5
6
7
8
|
<script>
function playSound(src){
var _s = document.getElementById(
'snd'
);
if
(src!=
''
&& typeof src!=undefined){
_s.src = src;
}
}
</script>
|