embed標籤動態改變Src的值,局部重新整理播放其他視頻的javascript方法

來源:互聯網
上載者:User

標籤:列表   image   sharp   eol   str   class   doc   視頻   list   

視頻處html代碼:
<div id="mod_player" class="mod_player">    <embed id="evideo" src="http://static.video.qq.com/TPout.swf?vid=d0110upcugq&auto=1" allowfullscreen="true" quality="high" width="650" height="472" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash">
</div>

 點擊右邊列表,左邊重新整理播放,開始的代碼:

$(document).ready(function(){  //點擊右邊列表的某個連結,視頻播放切換    $(‘#mod_videolist li‘).find(‘a‘).each(function(i, elem){        $(this).click(function(){           $(‘#mod_player > embed‘).attr(‘src‘, $(this).attr(‘href‘));           return false;        });      //document.getElementById(‘evideo‘).play();     });});

這樣只能切換embed的src值,但並不會切換播放(奇怪firefox能夠切換播放,其它瀏覽器只能改變了src),就是沒有觸發視頻的play動作,但因為不是html5的<video>標籤,embed標籤無法用js傳入play()方法,所以只能想別的方法,如下:

 $(document).ready(function(){    //點擊右邊列表的某個連結,視頻播放切換    $(‘#mod_videolist li‘).find(‘a‘).each(function(i, elem){       $(this).click(function(){           $(‘#mod_player > embed‘).remove();           var str = ‘<embed id="evideo" src="‘+ $(this).attr(‘href‘) +‘" allowfullscreen="true" quality="high" width="650" height="472" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash">‘;           $(‘#mod_player‘).html(str);           return false;        });    });});

通過“摧毀”embed,然後再改變embed的src的動態值,重建embed,這樣就能相容所有瀏覽器了。

embed標籤動態改變Src的值,局部重新整理播放其他視頻的javascript方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.