简体   繁体   English

HTML:如何从下拉列表中删除“无”

[英]HTML: how to remove “None” from a drop-down list

I have several drop-down lists in HTML, populated by data from an Excel sheet, which often, have empty cells/columns, so my drop-down lists become full of None (placeholder). 我有几个HTML下拉列表,由Excel工作表中的数据填充,通常有空单元格/列,因此我的下拉列表中充满了None(占位符)。

Ex.: Option 1
     ========
     Doctors
     Nurses
     None
     Month
     None

I cannot have these "None" removed in the backend, so I need a frontend solution. 我不能在后端删除这些“无”,所以我需要一个前端解决方案。 Any ideas? 有任何想法吗?

My code: 我的代码:

<div class="center_charts_menu_1">
  <select name="select_label" id="select_label" class="custom-select select_label">
    <option value="['1']" id="0" selected disabled hidden>lengend</option>
    <option value="{{ column_a }}" id='{{ label_a }}'>{{ label_a }}</option>
    <option value="{{ column_b }}" id='{{ label_b }}'>{{ label_b }}</option>
    <option value="{{ column_c }}" id='{{ label_c }}'>{{ label_c }}</option>
    <option value="{{ column_d }}" id='{{ label_d }}'>{{ label_d }}</option>
  </select>
</div>

your options id seems to have the same names. 您的选项ID似乎具有相同的名称。 So you can select all option-elements with the id="None" and remove it. 因此,您可以选择id =“None”的所有option-elements并将其删除。

 document.querySelectorAll('select > #None').forEach(e => e.remove()); 
 <select name="select_label" id="select_label" class="custom-select select_label"> <option value="['1']" id="0" selected disabled hidden>lengend</option> <option value="{{ column_a }}" id='Doctors'>Doctors</option> <option value="{{ column_b }}" id='Nurses'>Nurses</option> <option value="{{ column_c }}" id='None'>None</option> <option value="{{ column_d }}" id='Month'>Month</option> <option value="{{ column_d }}" id='None'>None</option> </select> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM