From 362ba6775c2337ed3dc91d5320f7e891c3c74f99 Mon Sep 17 00:00:00 2001 From: MDN Date: Sat, 13 Mar 2021 00:26:44 +0000 Subject: [CRON] sync translated content --- files/zh-cn/_redirects.txt | 2 +- files/zh-cn/_wikihistory.json | 12 ++-- .../zh-cn/web/api/document/getselection/index.html | 76 ++++++++++++++++++++++ .../documentorshadowroot/getselection/index.html | 75 --------------------- 4 files changed, 83 insertions(+), 82 deletions(-) create mode 100644 files/zh-cn/web/api/document/getselection/index.html delete mode 100644 files/zh-cn/web/api/documentorshadowroot/getselection/index.html (limited to 'files/zh-cn') diff --git a/files/zh-cn/_redirects.txt b/files/zh-cn/_redirects.txt index 9ee008a3bd..3908924a1b 100644 --- a/files/zh-cn/_redirects.txt +++ b/files/zh-cn/_redirects.txt @@ -1485,7 +1485,6 @@ /zh-CN/docs/Web/API/Document/domConfig /zh-CN/docs/Web/API/Document /zh-CN/docs/Web/API/Document/elementFromPoint /zh-CN/docs/conflicting/Web/API/DocumentOrShadowRoot/elementFromPoint /zh-CN/docs/Web/API/Document/elementsFromPoint /zh-CN/docs/conflicting/Web/API/DocumentOrShadowRoot/elementsFromPoint -/zh-CN/docs/Web/API/Document/getSelection /zh-CN/docs/conflicting/Web/API/DocumentOrShadowRoot/getSelection /zh-CN/docs/Web/API/Document/inputEncoding /zh-CN/docs/conflicting/Web/API/Document/characterSet /zh-CN/docs/Web/API/Document/mozFullScreen /zh-CN/docs/Web/API/Document/fullscreen /zh-CN/docs/Web/API/Document/mozFullScreenElement /zh-CN/docs/Web/API/Document/fullscreenElement @@ -1494,6 +1493,7 @@ /zh-CN/docs/Web/API/Document/rouchmove_event /zh-CN/docs/Web/API/Document/touchmove_event /zh-CN/docs/Web/API/DocumentOrShadowRoot/activeElement /zh-CN/docs/Web/API/Document/activeElement /zh-CN/docs/Web/API/DocumentOrShadowRoot/fullscreenElement /zh-CN/docs/Web/API/Document/fullscreenElement +/zh-CN/docs/Web/API/DocumentOrShadowRoot/getSelection /zh-CN/docs/Web/API/Document/getSelection /zh-CN/docs/Web/API/DocumentOrShadowRoot/pointerLockElement /zh-CN/docs/Web/API/Document/pointerLockElement /zh-CN/docs/Web/API/DocumentOrShadowRoot/styleSheets /zh-CN/docs/Web/API/Document/styleSheets /zh-CN/docs/Web/API/Document_Object_Model/Preface /zh-CN/docs/conflicting/Web/API/Document_Object_Model diff --git a/files/zh-cn/_wikihistory.json b/files/zh-cn/_wikihistory.json index 6bb3beb84a..524f81d1c5 100644 --- a/files/zh-cn/_wikihistory.json +++ b/files/zh-cn/_wikihistory.json @@ -10384,12 +10384,6 @@ "1Cr18Ni9" ] }, - "Web/API/DocumentOrShadowRoot/getSelection": { - "modified": "2020-10-15T22:12:59.602Z", - "contributors": [ - "WuCongMan" - ] - }, "Web/API/DocumentTouch": { "modified": "2019-03-23T22:57:10.414Z", "contributors": [ @@ -50798,5 +50792,11 @@ "contributors": [ "lastVigo" ] + }, + "Web/API/Document/getSelection": { + "modified": "2020-10-15T22:12:59.602Z", + "contributors": [ + "WuCongMan" + ] } } \ No newline at end of file diff --git a/files/zh-cn/web/api/document/getselection/index.html b/files/zh-cn/web/api/document/getselection/index.html new file mode 100644 index 0000000000..f3eca58f61 --- /dev/null +++ b/files/zh-cn/web/api/document/getselection/index.html @@ -0,0 +1,76 @@ +--- +title: DocumentOrShadowRoot.getSelection() +slug: Web/API/Document/getSelection +translation_of: Web/API/DocumentOrShadowRoot/getSelection +original_slug: Web/API/DocumentOrShadowRoot/getSelection +--- +
{{APIRef("DOM")}}{{SeeCompatTable}}
+ +

The getSelection() property of the {{DOMxRef("DocumentOrShadowRoot")}} interface returns a {{DOMxRef("Selection")}} object representing the range of text selected by the user, or the current position of the caret.

+ +

Syntax

+ +
var selection = documentOrShadowRootInstance.getSelection()
+ +

Parameters

+ +

None.

+ +

Returns

+ +

A {{DOMxRef("Selection")}} object.

+ +

Example

+ +
function foo() {
+    var selObj = document.getSelection();
+    alert(selObj);
+    var selRange = selObj.getRangeAt(0);
+    // do stuff with the range
+}
+ +

Notes

+ +

String representation of the Selection object

+ +

In JavaScript, when an object is passed to a function expecting a string (like {{DOMxRef("Window.alert()")}}), the object's {{JSxRef("Object.toString", "toString()")}} method is called and the returned value is passed to the function. This can make the object appear to be a string when used with other functions when it is really an object with properties and methods.

+ +

In the above example, selObj.toString() is automatically called when it is passed to {{DOMxRef("Window.alert()")}}. However, attempting to use a JavaScript String property or method such as length or substr directly on a {{DOMxRef("Selection")}} object results in an error if it does not have that property or method and may return unexpected results if it does. To use a Selection object as a string, call its toString() method directly:

+ +
var selectedText = selObj.toString();
+ + + + + +

HTML inputs provide simpler helper APIs for working with selection (see {{DOMxRef("HTMLInputElement.setSelectionRange()")}}).

+ +

Notice the difference between selection and focus. {{DOMxRef("Document.activeElement")}} returns the focused element.

+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("Shadow DOM", "#extensions-to-the-documentorshadowroot-mixin", "DocumentOrShadowRoot")}}{{Spec2("Shadow DOM")}}Initial definition.
+ +

Browser Compatibility

+ +
+ + +

{{Compat("api.DocumentOrShadowRoot.getSelection")}}

+
diff --git a/files/zh-cn/web/api/documentorshadowroot/getselection/index.html b/files/zh-cn/web/api/documentorshadowroot/getselection/index.html deleted file mode 100644 index 7110d24d21..0000000000 --- a/files/zh-cn/web/api/documentorshadowroot/getselection/index.html +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: DocumentOrShadowRoot.getSelection() -slug: Web/API/DocumentOrShadowRoot/getSelection -translation_of: Web/API/DocumentOrShadowRoot/getSelection ---- -
{{APIRef("DOM")}}{{SeeCompatTable}}
- -

The getSelection() property of the {{DOMxRef("DocumentOrShadowRoot")}} interface returns a {{DOMxRef("Selection")}} object representing the range of text selected by the user, or the current position of the caret.

- -

Syntax

- -
var selection = documentOrShadowRootInstance.getSelection()
- -

Parameters

- -

None.

- -

Returns

- -

A {{DOMxRef("Selection")}} object.

- -

Example

- -
function foo() {
-    var selObj = document.getSelection();
-    alert(selObj);
-    var selRange = selObj.getRangeAt(0);
-    // do stuff with the range
-}
- -

Notes

- -

String representation of the Selection object

- -

In JavaScript, when an object is passed to a function expecting a string (like {{DOMxRef("Window.alert()")}}), the object's {{JSxRef("Object.toString", "toString()")}} method is called and the returned value is passed to the function. This can make the object appear to be a string when used with other functions when it is really an object with properties and methods.

- -

In the above example, selObj.toString() is automatically called when it is passed to {{DOMxRef("Window.alert()")}}. However, attempting to use a JavaScript String property or method such as length or substr directly on a {{DOMxRef("Selection")}} object results in an error if it does not have that property or method and may return unexpected results if it does. To use a Selection object as a string, call its toString() method directly:

- -
var selectedText = selObj.toString();
- - - - - -

HTML inputs provide simpler helper APIs for working with selection (see {{DOMxRef("HTMLInputElement.setSelectionRange()")}}).

- -

Notice the difference between selection and focus. {{DOMxRef("Document.activeElement")}} returns the focused element.

- -

Specifications

- - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName("Shadow DOM", "#extensions-to-the-documentorshadowroot-mixin", "DocumentOrShadowRoot")}}{{Spec2("Shadow DOM")}}Initial definition.
- -

Browser Compatibility

- -
- - -

{{Compat("api.DocumentOrShadowRoot.getSelection")}}

-
-- cgit v1.2.3-54-g00ecf