<bgsound loop="0" src="flourish.mid"/>页面上加了上面的代码。
我想用一个按钮,停止播放这个声音,
请问JS怎么写?

解决方案 »

  1.   

    当然你也可以使用js将src设置为空就不播放了。
      

  2.   

    $('#player').src= '';这么写对吗?
      

  3.   

    网上 找的 楼主 试试<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>js控制背景音乐bgsound的方法(开始与停止)</title>
    </head><body>
    <script type="text/javascript">
    var bg_sound=document.createElement("bgsound");//创建背景音乐
    bg_sound.id="i_bg"//设置id属性
    document.body.appendChild(bg_sound);//body中添加背景音乐
    //bg_sound.src="ttmp3.mp3";
    i_bg.src="ttmp3.mp3";//设置一个背景音乐文件
    //应该也可以用write写出来,可以试下效果。
    function bg_stop(){
      i_bg.src="";
    }
    function bg_start(){
      i_bg.src="ttmp3.mp3";
    }
    </script>
    <span ><a onclick="javascript:bg_stop();" href="javascript:void(0);">背景音乐停止</a></span>  <span ><a onclick="javascript:bg_start();" href="javascript:void(0);">背景音乐开始</a></span>
    </body>
    </html>