研究了半天,不过貌似还是只能在IE上实现,其他浏览器不支持EMBED 标签
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用javascript制作超链接的背景音效</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function controlSound(action)
{
var i; method = "";
var sndObj = document.getElementById("music");
if (sndObj != null)
{
if (navigator.appName == 'Netscape')
method = "play";
else
{
if (window.MM_WMP == null)
{
window.MM_WMP = false;
for(i in sndObj)
{
if (i == "ActiveMovie")
{
window.MM_WMP = true;
//alert("1");
break;
}
}
}
if (window.MM_WMP)
method = "play";
else if (sndObj.FileName)
method = "run";
}
}
if (method)
{
if(action=="stop")
method="stop";
alert(method);
eval("document.hidden_player"+"."+method+"()");
}
}
//-->
</script>
</head>
<body>
<a href="#" onMouseOver="controlSound('play','document.ailisi','2.mp3')"
οnmοuseοut="controlSound('stop','document.ailisi','2.mp3')"
>背景音乐 鼠标移入播放 移出停
</a> <br>
<button οnclick="controlSound('play')">播</button>
<button οnclick="controlSound('stop')">停</button>
<!--src是音频的地址, hidden属性为隐藏-->
<EMBED NAME='hidden_player' SRC='1.wma' LOOP=false id="music"
AUTOSTART=false HIDDEN=true WIDTH=0 HEIGHT=0></EMBED>
</body>
</html>