简体   繁体   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. 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. I want to add search to it.我想向它添加搜索。 I tried Select2, but Couldn't implement correctly.我尝试了 Select2,但无法正确实现。 Need help The code is as follows需要帮助 代码如下

<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>

The JS: 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()
  }
});

Someone please correct me if I'm wrong here, but perhaps using a ternary for conditionally rendering the select would be easiest and simplest solution to decide if the HTML element renders?如果我在这里错了,请有人纠正我,但也许使用三元有条件地渲染 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">
}

You could use the DOM like so document.getelementbyid("the id of the element") or document.queryselector("the id of the element")您可以像这样使用 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