添加 class onclick 时,是否可以评估所有输入值,然后基于此重新调整 classes?

When adding a class onclick, is it possible to assess all input values and then readjust the classes based on that?

下午好,如果这比我看起来更明显,我深表歉意,

我很难将 classes 添加到某些输入区域,有没有办法将另一个 class 添加到输入,然后从这个操作中继续做更多,在一个精简的代码段。

这是我遇到的问题的稀释版本,因为我似乎无法让它工作,我仍然是 JavaScript 的新手,非常感谢任何建议。

<!DOCTYPE HTML>
<html>
<head>
<script src="jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    function checkSubmission(){
        var inputVal = document.getelementbyclassName("compulsory").value;
        if (inputVal == "") {
            $('this').addClass('redborder');
            window.location = "";
        }; 
        else if (inputVal != "" && document.getelementbyclassName('redborder')) {
            $('this').removeClass('redborder');
            window.location.href('');
        };
        else {
            window.location.href('');
        };
    };
    function checkFilled(){
        var inputFill = document.getelementbyclassName('redborder').value;
        if (inputFill != "") {
            document.getelementbyclassName('redborder').style.border-color = "green";
        }; 
    }; 
</script>
<style type="text/css">
    .redborder{
        border-color: red;
    }
</style>
</head>
<body>
    <button onclick="checkSubmission()">Change</button>
    <input class="compulsory">
</body>
</html>

如果您能提供帮助,非常感谢。

这是一个 "cleaned up" 版本,我怀疑它是否有效,但如果你将它与现有版本进行比较,你会看到上面提到的所有变化。

function checkSubmission() {
    var inputVal = document.getElementsByClassName("compulsory").value;
    if (inputVal == "") {
        $("this").addClass("redborder");
            window.location = "";
    } else if (inputVal !== "" && document.getElementsByClassName("redborder")) {
        $("this").removeClass("redborder");
            window.location.href("");
    } else {
        window.location.href("");
    }
}

function checkFilled() {
    var inputFill = document.getElementsByClassName("redborder").value;
    if (inputFill !== "") {
        document.getElementsByClassName("redborder").style.border = "thin solid green";
    }
}