JavaScript 替代 YouTube 嵌入源的功能? (无 iframe)
JavaScript function that alternates YouTube embed sources? (No iframe)
目的是点击 YouTube 视频嵌入代码(没有 iframe)的按钮来生成另一个 YouTube 视频嵌入代码 - 这是我的 HTML:
<p><button onClick="philscode()">Click Here!</button></p>
+
<div id="video0"><embed src="https://www.youtube.com/v/dP_ZPEMrJxY" wmode="transparent" type="application/x-shockwave-flash" width="200px" height="140px" allowfullscreen="true"></div>
我基本上需要将嵌入的 YouTube 视频(上图)替换为另一个 YouTube 视频。我也不想使用 jQuery。这是我目前拥有的JavaScript:
<script>
var embedcodes = ["https://www.youtube.com/watch?v=0vxq6K6yLm0"];
function philscode()
{document.getElementById("video0").innerHTML = embedcodes [0];
</script>
这里有一个演示 http://embed.plnkr.co/phmNaQD2JQa4RH8ITK0I
<script>
var embedcodes = ["http://www.youtube.com/v/XGSy3_Czz8k"];
function philscode()
{
var el = document.getElementById("video0Embed");
var clone=el.cloneNode(true);
clone.setAttribute('src', embedcodes [0]);
el .parentNode.replaceChild(clone,el );
}
</script>
<p><button onClick="philscode()">Click Here!</button></p>
<div id="video0">
<embed width="420" height="315" id="video0Embed"
src="https://www.youtube.com/v/dP_ZPEMrJxY">
</div>
目的是点击 YouTube 视频嵌入代码(没有 iframe)的按钮来生成另一个 YouTube 视频嵌入代码 - 这是我的 HTML:
<p><button onClick="philscode()">Click Here!</button></p>
+
<div id="video0"><embed src="https://www.youtube.com/v/dP_ZPEMrJxY" wmode="transparent" type="application/x-shockwave-flash" width="200px" height="140px" allowfullscreen="true"></div>
我基本上需要将嵌入的 YouTube 视频(上图)替换为另一个 YouTube 视频。我也不想使用 jQuery。这是我目前拥有的JavaScript:
<script>
var embedcodes = ["https://www.youtube.com/watch?v=0vxq6K6yLm0"];
function philscode()
{document.getElementById("video0").innerHTML = embedcodes [0];
</script>
这里有一个演示 http://embed.plnkr.co/phmNaQD2JQa4RH8ITK0I
<script>
var embedcodes = ["http://www.youtube.com/v/XGSy3_Czz8k"];
function philscode()
{
var el = document.getElementById("video0Embed");
var clone=el.cloneNode(true);
clone.setAttribute('src', embedcodes [0]);
el .parentNode.replaceChild(clone,el );
}
</script>
<p><button onClick="philscode()">Click Here!</button></p>
<div id="video0">
<embed width="420" height="315" id="video0Embed"
src="https://www.youtube.com/v/dP_ZPEMrJxY">
</div>