【发布时间】:2021-02-03 09:51:25
【问题描述】:
我有一个搜索选项,我可以在其中搜索页面中的元素,搜索操作正在运行,但我想在它不匹配任何元素时显示“未找到记录”消息
如果任何项目可见,它应该会自动隐藏
function filterFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
div = document.getElementById("myTableDropdown");
a = div.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
txtValue = a[i].textContent || a[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="dropdown"> <i class="fas fa-table btn dropdown-toggle p-0" onclick="lastSaved();" type="button" id="TabledropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></i>
<div id="myTableDropdown" class="dropdown-menu Organization_Desg_table_dropdown" aria-labelledby="TabledropdownMenuButton">
<form>
<label class="d-flex flex-row mb-0" style="padding: 4px 12px;">
<input type="text" placeholder="Search.." id="myInput" data-live-search="true" onkeyup="filterFunction()">
</label>
<hr class="m-0" /> <span id="errmsg"></span>
<a>
Designation Name,
</a>
<a >
Mail Alias,
</a>
<a >
Added By,
</a>
<a >
Added Time,
</a>
<a >
Modified By,
</a>
<a >
Modified Time,
</a>
<hr class="mt-1 mb-2" />
</form>
<div class="d-flex flex-row Organization_Desg_table_item">
<button>save</button>
</div>
</div>
</div>
【问题讨论】:
标签: javascript html css