Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Selection.addRange()

这篇翻译不完整。请帮忙从英语翻译这篇文章

概述

向选区(Selection)中添加一个区域(Range)。

语法

sel.addRange(range)

参数

range
一个区域(Range)对象将被增加到选区(Selection)当中。

例子

/* 在一个HTML文档中选中所有加粗的文本。 */

var strongs = document.getElementsByTagName("strong");
var s = window.getSelection();

if(s.rangeCount > 0) s.removeAllRanges();

for(var i = 0; i < strongs.length; i++) {
  var range = document.createRange();
  range.selectNode(strongs[i]);
  s.addRange(range);
}

Specifications

Specification Status Comment
HTML Editing APIs
Selection.addRange()
Editor's Draft Initial definition
Selection API
Selection.addRange()
Working Draft Current

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support ? (Yes) ? ? ?
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support ? (Yes) 1.0 ? ? ?

 

See also

文档标签和贡献者

 此页面的贡献者: RenGuangHui, teoli, khalid32, Losses
 最后编辑者: RenGuangHui,