如何用JavaScript改变嵌入src的值



我刚刚开始学习JS。我试图改变嵌入src的值在我的HTML代码中存在的标签。但我无法这样做与以下代码我写了-

HTML——

<ol>
<li><a href="http://embedgames.ru/wp-content/games/kitty-throw.swf" 
    onclick="showGame(this);return false;">Kitty Throw</a></li>
</ol>
<embed id="gameHolder" src="http://pictat.com/i/2011/7/10/32479playscrnba.jpg" 
    quality="high" menu ="false" width="550" height="400" 
    type="application/x-shockwave-flash" 
    pluginspage="http://www.macromedia.com/go/getflashplayer" /></center>

JS:

function showGame(whichgame){var source=whichgame.getAttribute("href");
var game=document.getElementById("gameHolder");
game.setAttribute("src",source);}

我希望JS显示在gameHolder空间中选择的flash文件,默认情况下保存图像。我无法做到这一点,只是我的初级知识的JS,也请解释代码,因为你使用它。

这可能取决于浏览器和嵌入对象的类型,以及如何更改对象(例如,有特殊的flash-movies方法,如Play(),但对象在开始时不是flash-movie)

一种常见的方法是用一个新的<embed>替换整个嵌入节点:

function showGame(whichgame){
  var source=whichgame.getAttribute("href");
  var game=document.getElementById("gameHolder");
  var clone=game.cloneNode(true);
  clone.setAttribute('src',source);
  game.parentNode.replaceChild(clone,game)
}

如果您只更改参数src

,它也可以工作

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
	<EMBED id="movie" src="first.swf" "></EMBED>
</OBJECT>
<ul>
	<li name='moviename'>first.swf</li>
	<li name='moviename'>second.swf</li>
	<li name='moviename'>third.swf</li>
</ul>
<script type="text/javascript">
	var names=document.getElementsByName("moviename");
	for (var i = names.length - 1; i >= 0; i--) {
		names[i].addEventListener("click", myFunction);
		function myFunction() {
    		document.getElementById("movie").setAttribute("src", this.innerHTML);
		}
	}
</script>

你可以在javascript中设置嵌入标签的SRC,为此你必须在javascript中编写你的嵌入标签,如下面的例子:

function onclickofSomething() {
    $('#IDOfParentElement').html("<embed type='application/x-mplayer2' pluginspage='http:///www.microsoft.com/Windows/MediaPlayer/' src='" + "<%=YourVideoPath%>" + "YourVideoName" + ID + ".mp4/wmv" + "' autostart='1' showstatusbar='1' enabled='1' showdisplay='1' showcontrols='1' width='630' height='380'></embed>");
}

你也可以看到下面的url:需要使用javascript设置视频文件名http://www.webdeveloper.com/forum/showthread.php?53086-how-to-change-the-src-in-lt-embed-gt-using-javascript http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/16626/how-to-change-the-the-value-of-src-in-embed-using-javascript

最新更新