JS 网页播放声音有多种方法可以实现,不过兼容各种浏览器的就没有几个了,不过本文的这个示例或许对大家有所帮助
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>
- SwfObject2.2Demo
- </title>
- <script type="text/javascript" src="swfobject.js">
- </script>
- <script type="text/javascript">
- var flashvars = {};
- var params = {
- wmode: "transparent"
- };
- var attributes = {};
- swfobject.embedSWF("sound.swf", "sound", "1", "1", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
- function play(c) {
- var sound = swfobject.getObjectById("sound");
- if (sound) {
- sound.SetVariable("f", c);
- sound.GotoFrame(1);
- }
- }
- </script>
- </head>
- <body>
- <div id="sound">
- </div>
- <input type="button" value="播放" onclick="play('msg.mp3')" />
- </body>
- </html>
需要的引入文件, 在 js 特效文件夹里面
来源: