单击JavaScript显示元素 [英] Javascript show element on click
本文介绍了单击JavaScript显示元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在没有Jquery的情况下这样做。我想在点击触发器时显示div。到目前为止,我有这个来隐藏元素。
document.getElementById('element')。style.display ='none';
HTML ..
< div class =element> Ahem,boo !!< / div>
< a href =#id =showDiv>显示< / a>
如何在点击链接时创建一个显示div的函数?我想避免使用如功能的onclick = showDiv()
在链接本身。
解决方案
document.getElementById('showDiv')。onclick = function(){
//删除任何元素特定的值,回退到样式表
document.getElementById('element')。style.display ='';
};
I'm trying to do this without Jquery. I want to show a div when clicking a trigger. So far I have this to hide the element.
document.getElementById('element').style.display = 'none';
HTML..
<div class="element">Ahem, boo!!</div>
<a href="#" id="showDiv">Show</a>
How do I create a function to show the div when clicking the link? I would like to avoid using functions like onclick="showDiv()
in the link itself.
解决方案
document.getElementById('showDiv').onclick=function(){
// Remove any element-specific value, falling back to stylesheets
document.getElementById('element').style.display='';
};
这篇关于单击JavaScript显示元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文