更新:在JavaScript中动态替换embed标签的src属性

时间:2010-11-22 03:54:12

标签: javascript jquery click embed movie

当我尝试更改嵌入式电影的src属性(quicktime)时,它奇怪地在Firefox中本地工作,但在firefox中的服务器上不起作用,在本地或服务器上的Safari中不起作用,并且它没有在IE中工作。

我尝试了下面建议的内容:

    $(".image_thumb ul li ul li").click(function(){     
var imgTitle = $(this).find('a').attr("href");  
var imgDesc = $(this).find('.block').html(); 
var imgDescHeight = $(".main_image").find('.block').height();   

if ($(this).is(".active")) {  
    return false; 
} else {
    alert(imgTitle);
    var videoClone = $(".main_image object").clone()
       .find("embed").attr({src: imgTitle}).end()  
       .find("param:first").attr({value: imgTitle});
    $(".main_image object").remove();
    $(".main_image").append(videoClone);

    $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
        $(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 );

    });
}
//more code

这根本不会使电影出现。一切都搞定了,但电影。谁知道为什么?当然,我不可能是唯一一个使用闪光灯以外的东西加载电影的人。

html(如果有帮助):

<div id="vid_wrapper">
    <div class="main_image">
        <object width="160" height="144"
        classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
        codebase="http://www.apple.com/qtactivex/qtplugin.cab">
        <param name="src" value="../images/Intro-1.mov">
        <param name="autoplay" value="true">
        <param name="controller" value="false">




        <EMBED SRC="../images/Intro-1.mov" WIDTH=500 HEIGHT=380 AUTOPLAY=true CONTROLLER=true LOOP=false PLUGINSPAGE="http://www.apple.com/quicktime/"> <!--    <img src="" alt="video_1"> -->
        </object>


        <div style="display: block;" class="desc">
            <a href="#" class="collapse">Close Me!</a>
            <div style="opacity: 0.85; margin-bottom: 0px; display: block;" class="block">
                    <h2>Video 1</h2>
                    <p>Autem conventio nimis quis ad, nisl secundum sed, facilisi, vicis augue regula, ratis, autem. Neo nostrud letatio aliquam validus eum quadrum, volutpat et.</p>
                </div>
        </div>
    </div>

    <div class="demo lists image_thumb">
            <ul>
              <li class="expand">Admin System
                <ul class="collapse">
                  <li class="active"> 

            <a href="../images/Intro-1.mov">
                <img src="../images/banner1_thumb.jpg" alt="video_1">
            </a>
            <div class="block">
                <h2>Video 1</h2>
                <p>Autem conventio nimis quis ad, nisl secundum sed, facilisi, vicis augue regula, ratis, autem. Neo nostrud letatio aliquam validus eum quadrum, volutpat et.</p>
            </div>
        </li>    
                  <li>
            <a href="../images/Intro-2.mov">
                <img src="../images/banner1_thumb.jpg" alt="video_2">
            </a>
            <div class="block">
                <h2>Video 2</h2>
                <p>Autem conventio nimis quis ad, nisl secundum sed, facilisi, vicis augue regula, ratis, autem. Neo nostrud letatio aliquam validus eum quadrum, volutpat et.</p>
            </div>
        </li>
                </ul>

              </li>
              <li class="expand">Enrollment System
                <ul class="collapse">
                  <li>
            <a href="../images/Intro-1.mov">
                <img src="../images/banner1_thumb.jpg" alt="video_3">
            </a>
            <div class="block">
                <h2>Video 3</h2>
                <p>Autem conventio nimis quis ad, nisl secundum sed, facilisi, vicis augue regula, ratis, autem. Neo nostrud letatio aliquam validus eum quadrum, volutpat et.</p>
            </div>
        </li>    

                  <li>
            <a href="video4.jpg">
                <img src="../images/banner1_thumb.jpg" alt="video_4">
            </a>
            <div class="block">
                <h2>Video 4</h2>
                <p>Autem conventio nimis quis ad, nisl secundum sed, facilisi, vicis augue regula, ratis, autem. Neo nostrud letatio aliquam validus eum quadrum, volutpat et.</p>
            </div>
        </li>
                </ul>
              </li>
              <li class="expand">Inventory System
                <ul class="collapse">

                  <li>
            <a href="video5.jpg">
                <img src="../images/banner1_thumb.jpg" alt="video_5">
            </a>
            <div class="block">
                <h2>Video 5</h2>
                <p>Autem conventio nimis quis ad, nisl secundum sed, facilisi, vicis augue regula, ratis, autem. Neo nostrud letatio aliquam validus eum quadrum, volutpat et.</p>
            </div>
        </li>

                  <li> 
            <a href="video6.jpg">
                <img src="../images/banner1_thumb.jpg" alt="video_6">
            </a>
            <div class="block">
                <h2>Video 6</h2>
                <p>Autem conventio nimis quis ad, nisl secundum sed, facilisi, vicis augue regula, ratis, autem. Neo nostrud letatio aliquam validus eum quadrum, volutpat et.</p>
            </div>
        </li>

                </ul>
              </li>
            </ul>    
        </div>
</div>  

感谢您的回复。

2 个答案:

答案 0 :(得分:0)

我没有使用嵌入式对象,但我猜测浏览器在加载后不响应对src属性的更改。

不知道这是否可行但是尝试克隆对象,删除现有对象,更改克隆对象上的属性,然后将其添加回文档。

这样的事情:

var videoClone = $(".main_image object").clone()
   .find("embed").attr({src: imgTitle}).end()  
   .find("param:first").attr({value: imgTitle});
$(".main_image object").remove();
$(".main_image").append(videoClone);

答案 1 :(得分:0)

尝试设置参数wmode =“transparent”,然后执行z-index事务..