检查复选框状态

时间:2018-10-14 19:53:27

标签: javascript asp.net-mvc

我为某些字段提供了一个全文本过滤器,并希望包括一个用于检查数字是否为<= 0

的过滤器。

您在这里看到了我的脚本代码以及HTML代码

我正在使用ASP.NET和一些ViewModels

    function filterResult() {
        var table, tr, i;
        table = document.getElementById("buchliste");
        tr = table.getElementsByTagName("tr");

        for (i = 0; i < tr.length; i++) {
            var td = tr[i].getElementsByTagName("td");

            if (
                td[0] && td[0].innerHTML.toUpperCase().indexOf(document.getElementById("katInput").value.toUpperCase()) > -1 &&
                td[1] && td[1].innerHTML.toUpperCase().indexOf(document.getElementById("titelInput").value.toUpperCase()) > -1 &&
                td[2] && td[2].innerHTML.toUpperCase().indexOf(document.getElementById("autorInput").value.toUpperCase()) > -1 &&
                td[3] && td[3].innerHTML.toUpperCase().indexOf(document.getElementById("isbnInput").value.toUpperCase()) > -1 &&
                td[4] && td[4].innerHTML.toUpperCase().indexOf(document.getElementById("buchBeschreibungInput").value.toUpperCase()) > -1 &&
                td[7] && td[7].innerHTML.toUpperCase().indexOf(document.getElementById("verfügbarInput").value.toUpperCase()) > -1 
            ) {
                tr[i].style.display = "";
            }
            else {
                tr[i].style.display = "none";
            }

        }
    }
 <details>
        <summary><label for="Liste filtern">Liste filtern</label></summary>
        <br />
        <div class="row">
            <div class="col-sm-2">

                <input class="form-control" type="text" id="katInput" onkeyup="filterResult()" placeholder="Kategorie" />
            </div>
            <div class="col-sm-2">

                <input class="form-control" type="text" id="titelInput" onkeyup="filterResult()" placeholder="Titel" />
            </div>
            <div class="col-sm-2">

                <input class="form-control" type="text" id="autorInput" onkeyup="filterResult()" placeholder="Autor" />
            </div>
            <div class="col-sm-2">

                <input class="form-control" type="text" id="isbnInput" onkeyup="filterResult()" placeholder="ISBN" />
            </div>
            <div class="col-sm-2">

                <input class="form-control" type="text" id="buchBeschreibungInput" onkeyup="filterResult()" placeholder="Buchbeschreibung" />
            </div>
            <div class="col-sm-2 ">
                <label>Verfügbar</label>
                <input class="checkbox-inline " type="checkbox" id="verfügbarInput" onkeyup="filterResult()" />
            </div>
        </div><br />
    </details>

在第7个索引上是带有一些整数值的字段。 复选框==verfügbarInput

我在另一个视图上还有另一个列表-我必须在最小和最大之间使用一些价格进行过滤-

有人可以帮助我利用这个问题吗?

2 个答案:

答案 0 :(得分:1)

只需获取它并使用hasAttribute函数

document.querySelector('.checkbox-inline').hasAttribute('checked');

答案 1 :(得分:0)

尝试

document.querySelector('.checkbox-inline:checked').value;
相关问题