我想在初次打开 HTML 文件时将该段落设置为“display:none”。然后使用 javascript 代码来显示/隐藏它。 这是我到目前为止所写的内容
HTML:
<hide1 class="inner" style="display.none;">
<p>hello</p>
</hide1>
JavaScript:
function tr1(obj)
{
var inner = document.getElementsByTagName("hide1")[0];
if (inner.style.display == "none")
inner.style.display = "";
else
inner.style.display = "none";
}
当我打开文件时,Hello 会显示,然后从显示切换到隐藏。我希望它默认隐藏并从隐藏切换到显示。
最佳答案
display.none;
这不是分配内联样式的正确方法。
使用display:none;
而不是使用display.none;
.
<hide1 class="inner" style="display:none;">
<p>hello</p>
</hide1>
注意:<hide1></hide1>
这不是一个有效的 html 标签。
试试这个:
HTML:
<div class="inner" style="display:none;">
<p>hello</p>
</div>
<input type="button" value="Click Here" onclick="toggle()">
Jquery
function toggle(){
$('.inner').toggle();
}
关于javascript - 设置默认显示:none for a section of text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24198335/