Home  >  Article  >  Web Front-end  >  js改变embed标签src值的方法_javascript技巧

js改变embed标签src值的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:04:481388browse

本文实例讲述了js改变embed标签src值的方法。分享给大家供大家参考。具体分析如下:

今天有一需求,一堆视频,一堆链接,点击相关的链接,在本页打开相关的视频。

第一想法,很简单么,直接把src值改成点击的那个的href值就可以了。

试了下,发现这样不行,视频该怎么放还是怎么放,永远是刚打开那个。

第二想法,给embed外面加个标签,把里面内容清空,再写进去,这样总可以了吧。

试了下,和上面一样,依旧不行。

又试了许多类似方法,还是不行。

最后,想的,把embed标签隐藏(display:none),再清空试下。终于可以了!

代码如下:

var tabv = document.getElementById("f_tabv");
var tabva = tabv.getElementsByTagName("a");
var tabcv = document.getElementById("f_tab_cv");
tabcv.innerHTML = '<EMBED src="abc.wmv" autostart="true"
width="545" height="325" type="video/x-ms-asf"></EMBED>';
for(var i=0; i<tabva.length; i++){
 tabva[i].onclick=function(){
 var href1 = this.getAttribute("href");
 var href2 = '<EMBED src="'+href1+'" autostart="true"
 width="545" height="325" type="video/x-ms-asf"></EMBED>';
 tabcv.getElementsByTagName("embed")[0].style.display="none";
 tabcv.innerHTML="";
 tabcv.innerHTML=href2;
 for(i=0; i<tabva.length; i++){
  tabva[i].className='';
 }
 this.className = "act";
 return false;
 }
}

希望本文所述对大家的javascript程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn