Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. Web API
  3. Document
  4. Document:selectionchange 事件

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

Document:selectionchange 事件

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年3月.

Selection APIselectionchange 事件在当前DocumentSelection 改变时触发。

此事件不可取消,也不会冒泡。

可以通过为selectionchange 添加事件监听器或使用onselectionchange 事件处理器来处理该事件。

备注:此事件与<input><textarea> 元素中的文本选择更改时触发的selectionchange 事件不太相同。有关详细信息,请参阅HTMLInputElement.selectionchange_event

语法

addEventListener() 等方法中使用事件名称,或设置事件处理器属性。

js
addEventListener("selectionchange", (event) => {});onselectionchange = (event) => {};

事件类型

通用Event

示例

js
// addEventListener 版本document.addEventListener("selectionchange", () => {  console.log(document.getSelection());});// onselectionchange 版本document.onselectionchange = () => {  console.log(document.getSelection());};

规范

Specification
Selection API
# selectionchange-event
Selection API
# dom-globaleventhandlers-onselectionchange

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp