我对某些字段有一个全文过滤器,并且希望包含一个过滤器来检查数字是否 <= 0
在这里您可以看到我的脚本代码和 HTML 代码
我正在使用 ASP.NET 和一些 ViewModel
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>
第七个索引是带有一些整数值的字段...... 复选框 == verfügbarInput
我在另一个 View 上还有另一个列表 - 我必须在最小值和最大值之间过滤一些价格 -
有人可以帮助我利用这个问题吗?
最佳答案
获取它并使用 hasAttribute 函数
document.querySelector('.checkbox-inline').hasAttribute('checked');
关于javascript - 检查复选框的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52806533/