这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
The type read-only property of the Selection interface returns a DOMString describing the type of the current selection.
语法
value = sel.type
Value
A DOMString describing the type of the current selection. Possible values are:
None: 当前没有选择。Caret: 选区已折叠(即 光标在字符之间,并未处于选中状态)。Range: 选择的是一个范围。
例子
In this example, the event handler will fire each time a new selection is made. console.log(selection.type) will return Caret or Range depending on whether the caret is placed at a single point in the text, or a range has been selected.
var selection;
document.onselectionchange = function() {
console.log('New selection made');
selection = document.getSelection();
console.log(selection.type);
};
Specifications
| Specification | Status | Comment |
|---|---|---|
| Selection API Selection.type |
Working Draft | Current |
Browser compatibility
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | 未实现 | (Yes) | (Yes) | ? |
| Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | ? | (Yes) | 未实现 | ? | ? | ? |