<Div id="Music_div"></DIV>
function chgMusic(src) {
  if (src) {
    documnet.all.Music_div.innerHTML ="<embed src='"+src+"'></embed>";
  } else { }}

解决方案 »

  1.   

    <html><head>
    <title>Control Music</title>
    <bgsound id=bs>
    </head><body topmargin="20" leftmargin="20">
    <script language=javascript>
    function setmusic(bs){
    this.bs=bs;
    this.musiclist=new Array(
    "0",
    "1",
    "2",
    "3",
    "4",
    "5",
    "6",
    "7",
    "8",
    "9",
    "10"
    );
    this.at=0;
    this.play=function(){
    this.bs.src="./mp3/"+this.musiclist[this.at]+".mp3";
    this.bs.loop=-1;
    }
    this.back=function(){
    this.at-=1;
    if(this.at<0)
    this.at=this.musiclist.length-1;
    this.play();
    }
    this.front=function(){
    this.at+=1;
    if(this.at>this.musiclist.length-1)
    this.at=0;
    this.play();
    }
    this.stop=function(){
    this.bs.src="";
    this.bs.loop=0;
    }
    }
    var music=new setmusic(document.all.bs);
    </script>
    <br><br>
    <TABLE WIDTH=47 BORDER=0 CELLPADDING=0 CELLSPACING=0 >
     <TR>
      <TD>
       <A HREF="javascript:music.back();">
        <IMG SRC="images/back.jpg" WIDTH=11 HEIGHT=11 BORDER=0 ALT="前一首"></A></TD>
      <TD>
       <A HREF="javascript:music.play();">
        <IMG SRC="images/go.jpg" WIDTH=12 HEIGHT=11 BORDER=0 ALT="播放"></A></TD>
      <TD>
       <A HREF="javascript:music.stop();">
        <IMG SRC="images/stop.jpg" WIDTH=12 HEIGHT=11 BORDER=0 ALT="停止"></A></TD>
      <TD>
       <A HREF="javascript:music.front();">
        <IMG SRC="images/front.jpg" WIDTH=12 HEIGHT=11 BORDER=0 ALT="后一首"></A></TD>
     </TR>
    </TABLE>
    </body>
    </html>
      

  2.   

    1   先用random()来随机
    2   在用随机出来的数字匹配背景音乐名
      

  3.   


    <SCRIPT language="JavaScript"><!--var sound1="song1.mid"var sound2="song2.mid"var sound3="song3.mid"var sound4="song4.mid"var sound5="song5.mid"var sound6="song6.mid"var sound7="song7.mid"var sound8="song8.mid"var sound9="song9.mid"var sound10="song10.mid"var x=Math.round(Math.random()*9)if (x==0) x=sound1else if (x==1) x=sound2else if (x==2) x=sound3else if (x==3) x=sound4else if (x==4) x=sound5else if (x==5) x=sound6else if (x==6) x=sound7else if (x==7) x=sound8else if (x==8) x=sound9else x=sound10if (navigator.appName=="Microsoft Internet Explorer")document.write('<bgsound src='+'"'+x+'"'+' loop="infinite">')else document.write('<embed src='+'"'+x+'"'+'hidden="true" border="0" width="20" height="20" autostart="true" loop="true">')
    //-->
    </SCRIPT>