非标
此特征是非标准的,且不在标准轨道中。不要在面向 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.

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

元数据

  • 最后修改: