在一个页面作一个有背景音乐的效果;
<embed src="" autostart="true" loop="true" hidden="true"></embed>
使用列表/菜单项,
 <select name="select2" onchange="javascript:location=this.options[this.selectedIndex].value;">
            <option>音乐</option>
            <option value="bg1.mp3">音乐1</option>
            <option value="bg2.wma">音乐2</option>
            <option value="bg3.wma">音乐3</option>
            <option>静音</option>
          </select>
想通过在下拉列表下选中一个值,然后直接将值传给<embed src="获取值">不使用提交按钮,请问可以实现嘛?

解决方案 »

  1.   

    给embed加个id,getElementByID获取对象后把下拉框选中的值赋给src属性没用过embed这个元素,但是DOM对象都是这么处理的吧
      

  2.   

    直接用JS来实现吧,挺简单的!
    哥给你写个看看行不?
    <embed id ="m" src="" autostart="true" loop="true" hidden="true"> </embed> 
     
    <select name="select2" onchange="javascript:fun_change(this);"> 
                <option>音乐 </option> 
                <option value="bg1.mp3">音乐1 </option> 
                <option value="bg2.wma">音乐2 </option> 
                <option value="bg3.wma">音乐3 </option> 
                <option>静音 </option> 
              </select> 
    <script>
      function fun_change(value){
          
          $("#m").css({src:value.value});
         //或是var val=getElementById("m").src=value.value;
        }</script>
      

  3.   

     $("#m").attr({src:value.value});用jquery 的话改成这个,上面那个错了,不是css 
      

  4.   

    我测试了一下,发现还是有错误,
    1、fun_change(value)与onchange="javascript:fun_change(this);的参数不符,
    2、修改后,用了JS两种方式还是不行,
    麻烦你在给想想,先谢谢你了。
      

  5.   

    $("#m").attr("src",$(value).val());
    是这样的吧,未经测试···
      

  6.   

    <script type="text/javascript"> 
      function fun_change(mvalue){ 
          
        
      $("#test_d").append("<b>Hello</b>");
        $("#test_d").append("<embed  src=./"+mvalue.value+ "autostart='true' loop='true' hidden='true'> </embed> ");
       
        } </script>
        我用jquery 做的可以用的!
      

  7.   

    <body>
      
        <embed id ="m" src="" autostart="true" loop="true" hidden="true"> </embed> 
    <div id="test_d">aa</div>
    <select name="select2" onchange="javascript:fun_change(this);"> 
                <option>音乐 </option> 
                <option value="bg1.mp3">音乐1 </option> 
                <option value="bg2.wma">音乐2 </option> 
                <option value="bg3.wma">音乐3 </option> 
                <option>静音 </option> 
              </select> 
              <div id='test_d'></div>
    <script type="text/javascript"> 
      function fun_change(mvalue){ 
          
        
     var mu="<embed  src=./"+mvalue.value + " autostart='true' loop='true' hidden='true'> </embed> ";
        $("#test_d").append(mu);
       alert(mu);
        } </script>
        
    </body>
      

  8.   


      echo "怎么发PHP源码??this is my test";
      

  9.   

    大哥呀,我不是把代码都发上去了嘛,
    思路是:onchange事件之后 ,
    在fun_change方法里,追加一个embed 标签。换一句话说,第change一次放一个MUSIC 应该是没有冲突的,我在本地测试已经好用了!!
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <script type="text/javascript" src="./js/jquery-1.3.2.min.js"></script><title>Insert title here</title>
    </head>
    <body>
     <embed id ="m" src="" autostart="true" loop="true" hidden="true"> </embed> 
    <div id='test'></div> //用于追加embed标签的,
    <select name="select2" onchange="javascript:fun_change(this);"> 
                <option>音乐 </option> 
                <option value="snow.mid">音乐1 </option> 
                <option value="bg2.wma">音乐2 </option> 
                <option value="bg3.wma">音乐3 </option> 
                <option>静音 </option> 
              </select> 
    <script> 
      function fun_change(mvalue){ 
          var val=document.getElementById("m");
        $("#test").append("<embed  src='./snow.mid' autostart='true' loop='true' hidden='true'> </embed> ");
        val.src="./"+mvalue.value; 
       
        } </script>
    </body>
    </html>
      

  10.   

    忘了告诉你了,你那个 <embed id ="m" src="" autostart="true" loop="true" hidden="true"> </embed> 我没用到!
      

  11.   

    郁闷了,我把代码都册了,
    再给你写一个!!
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <script type="text/javascript" src="./javascript/Login.js"></script>
    <script type="text/javascript" src="./javascript/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="./javascript/jquery-impromptu.2.5.js"></script>
    <title>Insert title here</title>
    </head>
    <body>
     <embed id ="m" src="" autostart="true" loop="true" hidden="true"> </embed> 
    <div id='test_d'></div> 
    <select name="select2" onchange="javascript:fun_change(this);"> 
                <option>音乐 </option> 
                <option value="snow.mid">音乐1 </option> 
                <option value="bg1.mp3">音乐2 </option> 
                <option value="bg3.wma">音乐3 </option> 
                <option>静音 </option> 
              </select> 
    <script> 
    function fun_change(mvalue){ 
        
        var i=1;
    var mu=" <embed id= "+i+ " src=./"+mvalue.value + " autostart='true' loop='true' hidden='true'> </embed> "; 
      $("embed").remove();
         $("#test_d").append(mu); 
       
      alert(mu); 

    </script>
    </body>
    </html>
    再不会,我就跳楼了!!
      

  12.   

    呵呵,我还真的把你教明白了,这个有个问题;
    1。如果你用,jquery 你的先下载下来,导入当前用的html页中,
    2。如果你不用也可以,别一种写法,用js 的CreateElement ,好像是这个,最好查一下。
    3.你确定,fun_change(mvalue)里的  $("#test_id") test_id 是你页面是的div 里的id
    4.自己用ie可以调试的,看看左下角有没有错误提示!
    16楼那个代码完全正确的,
    机子是不可能出问题的,问题还是出在程序上面了!关键是找出错误。
      

  13.   

    之前不知道使用jquery还要导入这个JS文件,真是惭愧呀,
    我导入了Jquery后,提示:<embed id= 1 src=[object] autostart='true' loop='true' hidden='true'> </embed>这是什么原因呢
      

  14.   

     
        $("embed").remove(); //这个就是消除重复的。
         $("#test_d").append(mu); 
      

  15.   

    我真的不知道怎么和你说了,有时候多研究一下,jquery吧,还有程序的调试方法,
    和你说的很明白了,16楼的代码完全没有错误的,