繁体   English   中英

HTML Select 带搜索选项

[英]HTML Select With Search Option

I have a simple HTML Select, When the user enters the data in the text box if the data entered is Less than some percentage this HTML Select is displaed else it is hidden. 我想向它添加搜索。 我尝试了 Select2,但无法正确实现。 需要帮助 代码如下

<select name="reason" id="reason#getProdInfo.currentRow#" style="display: none">
<option>--</option>
<option>Line feeding not available</option>
<option>WIP not available</option>  
<option>Absenteeism issue</option>
<option>Operator on other operation issue</option>
<option>Reworking due to high DHU</option>
<option>Re-check</option>
<option>Operator training issue</option>
<option>Machine out of order</option>
<option>Operator low efficiency</option>
<option>Trolley not available</option>
<option>Line feeding late arrived</option>
<option>Operator working on extra work</option>
<option>Operator late arrived</option>
<option>Engineering Support not available  </option>
</select>

JS:

$('#prods1').on('focusout', function(){
  var element1 = document.getElementById("prods1").value;
  var element2 = document.getElementById("trgt").value;
  var calc = (element1/element2)*100
  if (calc<70){
    $("#reason1").show()
  }else{
    $("#reason1").hide()
  }
});

如果我在这里错了,请有人纠正我,但也许使用三元有条件地渲染 select 将是决定 HTML 元素是否渲染的最简单和最简单的解决方案?

{userInput.length > 0 
    ? <select name="reason" id="reason#getProdInfo.currentRow#" style="display: block"> 
    : <select name="reason" id="reason#getProdInfo.currentRow#" style="display: none">
}

您可以像这样使用 DOM document.getelementbyid("the id of the element")document.queryselector("the id of the element")

暂无
暂无

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

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