非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
search
event is fired when a search is initiated usinng an
<input>
元素的
type="search"
.
| 冒泡 | Yes |
|---|---|
| 可取消 | No |
| 接口 |
事件
|
| 事件处理程序特性 |
onsearch
|
There are several ways a search can be initiated, such as by pressing
Enter
while the
<input>
is focused, or, if the
incremental
attribute is present, after a UA-defined timeout elapses since the most recent keystroke (with new keystrokes resetting the timeout so the firing of the event is debounced).
Current UA implementations of
<input type="search">
have an additional control to clear the field. Using this control also fires the
search
event. In that case the
value
的
<input>
element will be the empty string.
// addEventListener version
const input = document.querySelector('input[type="search"]');
input.addEventListener('search', () => {
console.log("The term searched for was " + input.value);
})
// onsearch version
const input = document.querySelector('input[type="search"]');
input.onsearch = () => {
console.log("The term searched for was " + input.value);
})
This event is not part of any specification.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
search
event
非标
|
Chrome Yes | Edge 79 | Firefox No | IE No | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android No | Opera Android ? | Safari iOS ? | Samsung Internet Android Yes |
完整支持
不支持
兼容性未知
非标。预期跨浏览器支持较差。