用于向外折叠车窗和向内折叠所有其他车窗的代码

Code for folding out a window and folding in all others

本文关键字:车窗 折叠 其他 代码 用于      更新时间:2023-12-25

函数foldout工作得很好,但我希望第二个函数先运行,先关闭所有其他元素,但我不知道出了什么问题;谢谢你的帮助!

编辑。第二个函数似乎无法工作或关闭已打开的表单。

编辑。感谢大家的回答;明天我会有更多的时间阅读和尝试一切。

functions.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";
            }
        }
};

page.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>