如何在默认情况下隐藏切换 [英] How to make toggle hidden by default
本文介绍了如何在默认情况下隐藏切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我想知道如何在页面加载时隐藏切换,我编写了一个简单的代码,但是在页面加载时默认情况下会显示它.我要解决这个问题.
Hello I would like to know how to make toggle hidden when the page loads, I have made a simple code, but when the page loads it will be shown by default. I want it the way around.
我必须尝试使用CSS之类的东西
I have to tried to use CSS something like
.hidden {
display:none;
}
当我使用此代码时,该元素完全不显示.
when I use this code, the element doesn't show at all.
这是我的代码
已编辑
<script type="text/javascript">
function toggleDiv(divId) {
$("#"+divId).toggle();
}
</script>
<a href="javascript:toggleDiv('myContent');">this is a test</a>
<div id="myContent">
<a href="javascript:toggleDiv('myContentt');"><span>this is a text</span></a>
<div>this is a test #2 </div>
</div>
<div id="myContentt">
test
</div>
请帮助.
推荐答案
我想,您想要这样的东西,
I guess, you want something like this,
演示(我在演示中使用了onclick
,因为jsfiddle不喜欢href
上的javascript)
Demo ( I used onclick
in demo because jsfiddle doesnt like javascript on href
)
CSS:
.hidden{
display:none;
}
标记:
<a href="javascript:toggleDiv('myContent');">this is a test</a>
<div id="myContent" class='hidden'>
<div>this is a test #1 </div>
</div>
<br />
<a href="javascript:toggleDiv('myContentt');"><span>this is a text</span></a>
<div id="myContentt" class='hidden'>
this is a test #2
</div>
Javascript:
function toggleDiv(divId) {
$("#"+divId).toggle();
}
这篇关于如何在默认情况下隐藏切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文