+ -
当前位置:首页 → 问答吧 → 请教各位,网页中如何做到点击一个链接播放背景音乐

请教各位,网页中如何做到点击一个链接播放背景音乐

时间:2010-05-23

来源:互联网

希望有人能帮忙,我需要当点击页面中一个链接时播放一段音乐,如何设置这样的代码?

作者: wenjfei   发布时间: 2010-05-23


<!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" lang="gb2312"> <head> <title>music</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <style type="text/css"> #play, #stop {cursor:pointer;float:left;margin-right:15px;} </style> <script type="text/javascript"> function $(id) { return typeof id=="string"?document.getElementById(id):id;} function createPlayer(url) { var box=document.createElement("div"); box.style.cssText="width:0px;height:0px;overflow:hidden;visibility:hidden;"; document.body.appendChild(box); if(!!window.ActiveXObject) { box.innerHTML="<object classid='clsid:6bf52a52-394a-11d3-b153-00c04f79faa6' id='mplayer' width='300' height='200'><param name='url' value='"+url+"' /><param name='uiMode' value='None' /><param name='AutoStart' value='0' /></object>"; } else { box.innerHTML="<object type='application/x-ms-wmp' id='mplayer' width='300' height='200'><param name='url' value='"+url+"' /><param name='AutoStart' value='false' /></object>"; } } window.onload=function(){ createPlayer("http://cs.gzedu.com/jiaoshijixu/dbsd8/jxjy022/text/chapter6/audio/wdzgx.mp3"); var MediaPlayer=$("mplayer"); $("play").onclick=function(){MediaPlayer.controls.play();}; $("stop").onclick=function(){MediaPlayer.controls.stop();}; }; </script> </head> <body> <span id="play">播放</span><span id="stop">停止</span> </body> </html>
 提示:您可以先修改部分代码再运行
[ 本帖最后由 michaellu 于 2010-5-24 10:24 编辑 ]

作者: michaellu   发布时间: 2010-05-23

谢谢2楼michaellu。。。

作者: wenjfei   发布时间: 2010-05-24