javascript - 动态更改标签的可见性
问题描述
解决方案
您需要将代码包装在委托的事件处理程序中
数组的长度不能 < 0
const incidentsArray = [];
// The custom toolbar element
let html = `<b>Filter by:</b> <select id='crs-selection'>
<option value="1" class='client-specific'>Specific</option>
<option value="2">All</option>
</select><b id='crs-checker'>No Client logged CRs present</b>`;
$("div.toolbar").html(html);
$("div.toolbar").on("change","#crs-selection", function() {
const crx = $(this).val();
$("#crs-checker").toggle(incidentsArray.length === 0 && crx != 2)
}).change(); // on load
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="toolbar"></div>
推荐阅读
- ionic-framework - 如何在网络浏览器视图中从我的 Ionic 应用程序打开外部链接
- android - 在矩形内绘制圆角
- android - 如何将谷歌地图上的交通数据解析为json?
- javascript - 地图 Js 中的逗号
- javascript - 如果在选择器中使用变量,则未正确选择子元素
- java - 找不到符号 [ERROR] 符号:方法 getlogger(java.lang.Class
) - sql - SAP HANA -count(*) 给出不同的输出
- c# - 如何使用 ASP.NET 和 C# 在 Gridview 中实现批量保存
- javascript - 如何使用 Jest 和 Enzyme 测试具有 Router、Redux 和两个 HOC 的 React 组件?
- javascript - Node.js child_process TypeError:无法读取未定义的属性“_writableState”