我有这个脚本,当我点击一个按钮时它会被执行。单击该按钮时,下面的文本将折叠,当我再次单击该按钮时,文本将展开并查看。
但是,我想要的恰恰相反。当页面自行加载时,我想隐藏/折叠文本并仅在单击按钮时显示。
我怎样才能做出改变?
JS
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;
}
HTML
<input type="button" ="return toggleMe('para1')" value="Toggle">
<br>
<p id="para1">
some text................ </p>
最佳答案
改变
<p id="para1">
to
<p id="para1" style="display: none">
这行得通吗?
关于javascript - 折叠/展开文本 - 逻辑错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14674474/