首页 > 解决方案 > 动态更改标签的可见性

问题描述

标签: javascriptjquerydatatables

解决方案


您需要将代码包装在委托的事件处理程序中

数组的长度不能 < 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>


推荐阅读