函数折叠工作完美,但我希望第二个函数首先运行以首先关闭所有其他元素,但我不知道出了什么问题;谢谢您的帮助!
编辑。第二个功能似乎不起作用或关闭已经打开的表单。
编辑。谢谢大家的回答;明天我将有更多时间阅读并尝试一切。
函数.js:
function foldout(fold) {
if (document.getElementById) {
var fold = document.getElementById(fold).style;
if (fold.display == "block") {
fold.display = "none";
} else {
fold.display= "block";
}
return false;
} else {
return true;
}
};
function foldall () {
var foldall = document.getElementsByClassName('foldall');
for(var i=0; i<foldall.length; i++) {
var foldthis = foldall[i];
if (foldthis.display == "block") {
foldthis.display = "none";
}
}
};
页面.php:
<a href="#" onclick="foldall('foldall'); return foldout('fold');"> </a>
<form method="POST" style="display: none;" class ="foldall" id="fold">
</form
最佳答案
尝试从 foldout
函数调用 foldall
函数:
function foldall () {
var foldall = document.getElementsByClassName('foldall');
for(var i=0; i<foldall.length; i++) {
var foldthis = foldall[i];
if (foldthis.display == "block") {
foldthis.display = "none";
}
}
};
function foldout(fold) {
foldall(); // collapse everything
if (document.getElementById) {
var fold = document.getElementById(fold).style;
if (fold.display == "block") {
fold.display = "none";
} else {
fold.display= "block";
}
return false;
} else {
return true;
}
};
并且仅从 onclick
处理程序中调用折叠:
<a href="#" onclick="foldout('fold');"></a>
<form method="POST" style="display: none;" class ="foldall" id="fold"></form>
关于javascript - 折叠 window 并折叠所有其他 window 的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20273283/