更新:动态替换 JavaScript 中嵌入标签的 src 属性

发布于 2024-10-03 16:23:59 字数 5814 浏览 8 评论 0原文

当我尝试更改嵌入电影(quicktime)的 src 属性时,它在 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>  

感谢您的回复。

When I try to change the src attribute of embedded movie (quicktime), it strangely works locally in Firefox, but doesn't work on server in firefox, doesn't work in Safari either locally or on server, and it doesn't work in IE.

I try what was suggested below:

    $(".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

This doesn't make the movie appear at all. Everything gets loaded but movie. Anyone know why? Surely, I can't be the only one using something other than flash to load movies.

html (if helpful):

<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>  

Thanks for any response.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情域 2024-10-10 16:23:59

我没有使用过嵌入对象,但我猜测浏览器在加载后不会响应 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);

I haven't worked with embedded objects, but I'm guessing that the browser doesn't respond to changes to the src attribute after it has been loaded.

No idea if this will work but try cloning the object, removing the existing one, changing the attributes on the cloned object, and then adding it back into the document.

Something like this:

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);
z祗昰~ 2024-10-10 16:23:59

尝试设置参数 wmode="transparent" 然后执行 z-index 操作..

try setting the Parameter wmode="transparent" and then do the z-index thing..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文