单击时用另一个div替换div
问题描述:
现在我想要的是#youtube随时显示,但如果单击它,我想将其转换为#embed。无法让它工作。我的意思是,它不做我刚刚解释的。什么都没发生。单击时用另一个div替换div
<div id="youtube" onclick="replace()" style="display:block">
<img src="http://img.youtube.com/vi/'.$id.'/1.jpg">
<span class="title"><font color="#999">YouTube™ Video:</font> '.$title.'</span>
<span class="views">Views: '.number_format($views).'</span>
<span class="description">'.$desc.'</span>
</div>
// show this only if they clicked on #youtube
<div id="embed" onclick="replace()" style="display:none">
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/$1?fs=1"</param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<embed src="http://www.youtube.com/v/$1?fs=1"
type="application/x-shockwave-flash" allowscriptaccess="always" allowFullScreen="true" width="425" height="344">
</embed>
</object>
</div>
JS:
答
你错过了周围的DIV名字报价在getElementById
:
function replace() {
document.getElementById("youtube").style.display="none";
document.getElementById("embed").style.display="block";
}
getElementById
接受一个字符串,嵌入是一个标识符名字,你需要使用一个字符串文字通过用刻度包装它。
答
只需注明您的div的名字
document.getElementById('youtube').style.display="none";
document.getElementById('embed').style.display="block";
[了解如何** **调试JavaScript的(http://www.netmagazine.com/tutorials/javascript-debugging-beginners)。 –