显示隐藏的div
嗨,当用户单击 more img 链接时,我尝试显示我的 div para2 中的内容,
我以前使用过此代码并且它有效,但我现在不会了?
请指出我的错误,我只是初学者,
提前谢谢
<blockquote>
<p>
<a href="#para2"/>
<a href="#" onclick="return toggleMe('para2')" onfocus="#para2"/> <img src="images/more.gif" alt="" title="" border="0"></a>
<div id="para2" style="display:none">
text i want to reveal
</div>
</p>
</blockquote>
抱歉
<script type="text/javascript">
function toggleMe(a){
var e=document.getElementById(a);
if(!e)return true;
if(e.style.display=="none"){
e.style.display="block"
}
else{
e.style.display="none"
}
return true;
}
</script>
</head>
hi i am try to reveal the content in my div para2 when the user clicks the more img link
i have used this code before and it worked but i wont now ??
Please point out my mistakes i am only a beginner
thanks in advance
<blockquote>
<p>
<a href="#para2"/>
<a href="#" onclick="return toggleMe('para2')" onfocus="#para2"/> <img src="images/more.gif" alt="" title="" border="0"></a>
<div id="para2" style="display:none">
text i want to reveal
</div>
</p>
</blockquote>
sorry
<script type="text/javascript">
function toggleMe(a){
var e=document.getElementById(a);
if(!e)return true;
if(e.style.display=="none"){
e.style.display="block"
}
else{
e.style.display="none"
}
return true;
}
</script>
</head>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如@Kolink所说,onfocus是错误的。尝试这样的事情...
http://jsfiddle.net/gL37n/5/
As @Kolink said onfocus is wrong. Try something like this...
http://jsfiddle.net/gL37n/5/
#para2
不是有效的 JavaScript 代码,因此您不能将其用作onfocus
属性。由于您在那里遇到语法错误,因此它也可能突破了
onclick
代码,因此无法运行它。尝试删除
onfocus
属性,看看是否可以解决问题。#para2
is not a valid piece of javascript code, so you can't use it as anonfocus
attribute.Since you're getting a syntax error there, it is possible that it's breaking out of the
onclick
code as well, therefore not running it.Try removing the
onfocus
attribute, and see if that fixes it.