简体   繁体   English

选择/选项元素的默认“搜索”行为是什么?

[英]What is the default “search” behavior on select/option elements?

I have a Select element that has Option elements with value and text attributes like so: 我有一个Select元素,其中的Option元素具有值和文本属性,如下所示:

<select>
  <option value="">-Select-</option>
  <option value="Ok">Ok</option>
  <option value="Orc">Orc</option>
  <option value="Oops">Oops</option>
  <option value="7">7</option>
  <option value="78">78</option>
  <option value="77">77</option>
</select>

Codepen here: http://codepen.io/k/pen/rIbhv 此处的Codepen: http ://codepen.io/k/pen/rIbhv

Focusing on the Select and pressing "O" or "7" will select "Ok" or "7", respectively. 专注于选择并按“ O”或“ 7”将分别选择“确定”或“ 7”。

Pressing "Oo" or "77" will select "Orc" or "78". 按“ Oo”或“ 77”将选择“ Orc”或“ 78”。

Can someone explain why and/or how the select (or is it the option) element behaves this way? 有人可以解释为什么(和/或选择)元素以这种方式表现吗? Why is the next option selected, and not the one that was "searched" for? 为什么选择下一个选项,而不选择“搜索”的下一个选项? Is this default search behavior outlined anywhere? 该默认搜索行为在任何地方都有概述吗? I tried looking at the w3c docs but was unsuccessful. 我尝试查看w3c文档,但未成功。

I would like to implement a custom search functionality in the future, but wanted to first understand the default search behavior in hopes that it would help my coding. 我想在将来实现自定义搜索功能,但想首先了解默认搜索行为,以期对我的编码有所帮助。

Any pointers would be appreciated. 任何指针将不胜感激。

It is implementation-specific, but the general "standard" seems to be: 它是特定于实现的,但是一般的“标准”似乎是:

  • If you hit the same key repeatedly, cycle through the items starting with that letter. 如果您反复按相同的键,请循环浏览以该字母开头的项目。
  • If you appear to be typing by pressing different keys, search for that item. 如果您似乎要通过按其他键来键入内容,请搜索该项目。

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

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