InputEvent.getTargetRanges() - Web APIs 编辑
The getTargetRanges()
method of the InputEvent
interface returns an array of static ranges that will be affected by a change to the DOM if the input event is not canceled.
Syntax
var staticRanges[] = inputEvent.getTargetRanges()
Parameters
None.
Return value
An array of StaticRange
objects.
Examples
Feature Detection
The following function returns true if beforeinput
, and thus getTargetRanges
, is supported.
function isBeforeInputEventAvailable() {
return window.InputEvent && typeof InputEvent.prototype.getTargetRanges === "function";
}
Basic usage
The following example selects a contenteditable
element and utilises the beforeinput
event to log the result of getTargetRanges()
.
const editableElem = document.querySelector('[contenteditable="true"]');
editableElem.addEventListener('beforeinput', (e) => {
const targetRanges = e.getTargetRanges();
console.log(targetRanges);
})
Specifications
Specification | Status | Comment |
---|---|---|
Input Events Level 2 The definition of 'getTargetRanges()' in that specification. | Working Draft | Initial definition. |
Browser Compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论