javascript - 运行以下 javascript 后搜索字段不起作用
问题描述
<div class="row col-lg-8 col-md-12 col-sm-12 mt-2">
<label class="switch ml-2 mr-2">
<input type="checkbox" id="switch-exp" value='off'>
<span class="slider slider2 round"></span>
</label>
<h5 class="mr-3 mt-2" style="font-size: 20px;">Abonos vencidos</h4>
<br>
<label class="switch switch-close ml-2 mr-2">
<input type="checkbox" id="switch-close" checked value='on'>
<span class="slider round"></span>
</label>
<h5 class="mt-2" style="font-size: 20px;">Abonos por vencer</h4>
</div>
<!-- butt
<span class="counter pull-top"></span>
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-hover border results table-striped mb-0">
<thead>
<tr>
<th></th>
<th>Nombre / Apellido</th>
<th>Nro documento</th>
<th>Nro de teléfono</th>
<th>horario</th>
<th>Fecha vencimiento</th>
<th>Note</th>
</tr>
<tr class="warning no-result table-danger">
<td colspan="7" style="font-size: 20px; text-align: center;"><i class="fa fa-warning"></i> sin resultados</td>
</tr>
</thead>
<tbody>
{% if customers %}
{% for customer in customers %}
<tr class="table-{{customer.category}} {{customer.category}}">
{% if customer.user.image %}
<th scope="row"><a href="{% url 'core:user_detail' customer.user.id %}"><img src="{{customer.user.image.url}}" alt="customer-img" style="width: 50px; height: 50px;"></a></th>
{% else %}
<th scope="row"><a href="{% url 'core:user_detail' customer.user.id %}"><img src="https://upload.wikimedia.org/wikipedia/commons/7/72/Default-welcomer.png" alt="customer-img" style="width: 50px; height: 50px;"></a></th>
{% endif %}
<td>{{customer.user.first_name}}/{{customer.user.last_name}}</td>
<td>{{customer.user.id}}</td>
<td>{{customer.user.phone_no}}</td>
<td>{{customer.user.time}}</td>
<td>{{customer.expiration_date.date}}</td>
<td>{{customer.user.note}}</td>
</tr>
{% endfor %}
{% else %}
<tr class="table-{{customer.category}}">
No hay clientes disponibles
</tr>
{% endif %}
</tbody>
</table>
</div>
document.querySelectorAll('.switch').forEach(switchs => switchs.addEventListener('click',(event)=>{
if(event.target.id === 'switch-close'){
if (event.target.value === 'off'){
event.target.value='on';
document.querySelectorAll('#danger').forEach(items => items.style.display='none');
document.querySelectorAll('#warning').forEach(items => items.style.display='table-row');
document.querySelectorAll('#success').forEach(items => items.style.display='none');
}
else if (event.target.value === 'on'){
event.target.value = 'off';
document.querySelectorAll('#danger').forEach(items => items.style.display='table-row');
document.querySelectorAll('#success').forEach(items => items.style.display='table-row');
document.querySelectorAll('#warning').forEach(items => items.style.display='table-row');
}
}
else if (event.target.id==='switch-exp'){
if (event.target.value === 'off'){
event.target.value='on';
document.querySelectorAll('#danger').forEach(items => items.style.display='table-row');
document.querySelectorAll('#warning').forEach(items => items.style.display='none');
document.querySelectorAll('#success').forEach(items => items.style.display='none');
}
else if (event.target.value === 'on'){
event.target.value = 'off';
document.querySelectorAll('#danger').forEach(items => items.style.display='table-row');
document.querySelectorAll('#success').forEach(items => items.style.display='table-row');
document.querySelectorAll('#warning').forEach(items => items.style.display='table-row');
}
}
}) )
这是一个健身房管理系统,我有表格和从表格中搜索数据的搜索栏,并且有两个开关显示过期的会员用户和即将过期的会员用户
当我在搜索框中搜索时,表格正常工作根据搜索字段输入找到的数据并且所有表格行都消失了,但是只要我单击任何开关按钮,找到的搜索字段数据但所有其他行都不会消失仍然在屏幕上。javascript 在下面的下方 javascript 不适用于搜索字段,它适用于我单击的开关,而不是搜索的数据显示,但未删除其他未搜索的字段。
解决方案
推荐阅读
- linux - 如何在bash中检查空环境变量
- slack - 删除 slack 中提醒生成的消息
- c++ - 使用 Ceres 优化多维函数
- z3 - Z3Py 如何使用 Pi 和 e
- ruby - 日志存储。使用 ruby 脚本的嵌套对象映射
- java - 在 tomcat v 8.5 上部署 Spring Boot 应用程序失败
- angular - 在 IIS 10 上部署时应用程序根无法正常工作
- php - 按与每个类别关联的会议数量对类别进行排序
- mysql - mysql 按日期分组,左连接表使用按日期分组
- sql-server - 如何将存储在表中的 IP 地址转换为十六进制?对于 IP 141.105.223.182,我期望的输出是 00:00:8D:69:DF:B6