Java 输入至少 2 个数字后检查并激活 substr

Java substr to check and activate after typing at least 2 numbers

在字段中输入至少 2 个数字后,如何使用 substr 激活。

if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
          /*create a DIV element for each matching element:*/
          b = document.createElement("DIV");
          /*make the matching letters bold:*/
          b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
          b.innerHTML += arr[i].substr(val.length);
          /*insert a input field that will hold the current array item's value:*/
          b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
          /*execute a function when someone clicks on the item value (DIV element):*/
          b.addEventListener("click", function(e) {
              /*insert the value for the autocomplete text field:*/
              inp.value = this.getElementsByTagName("input")[0].value;
              /*close the list of autocompleted values,
              (or any other open lists of autocompleted values:*/
              closeAllLists();
          });
          a.appendChild(b);
        }
      }
  });

它是一个 W3 的东西,可以自动完成你的发件人,但它开始显示 1 个字母,那太快了。

我试过 val.length>

但运气不好

w3 link 本身在这里 https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_autocomplete

检查val长度,更改

closeAllLists();
if (!val) { return false;}

closeAllLists();
if (!val || val.length < 2) { return false;}