From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/element/insertadjacenttext/index.html | 151 +++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 files/zh-cn/web/api/element/insertadjacenttext/index.html (limited to 'files/zh-cn/web/api/element/insertadjacenttext/index.html') diff --git a/files/zh-cn/web/api/element/insertadjacenttext/index.html b/files/zh-cn/web/api/element/insertadjacenttext/index.html new file mode 100644 index 0000000000..39d8af60fe --- /dev/null +++ b/files/zh-cn/web/api/element/insertadjacenttext/index.html @@ -0,0 +1,151 @@ +--- +title: Element.insertAdjacentText() +slug: Web/API/Element/insertAdjacentText +tags: + - Element.insertAdjacentText() +translation_of: Web/API/Element/insertAdjacentText +--- +

{{APIRef("DOM")}}

+ +

insertAdjacentText() 方法将一个给定的文本节点插入在相对于被调用的元素给定的位置。

+ +

句法

+ +
element.insertAdjacentText(position, element);
+ +

参数

+ +
+
position
+
A {{domxref("DOMString")}} representing the position relative to the element; must be one of the following strings: +
    +
  • 'beforebegin': Before the element itself.
  • +
  • 'afterbegin': Just inside the element, before its first child.
  • +
  • 'beforeend': Just inside the element, after its last child.
  • +
  • 'afterend': After the element itself.
  • +
+
+
element
+
A {{domxref("DOMString")}} representing the text to be inserted into the tree.
+
+ +

返回值

+ +

Void.

+ +

例外

+ + + + + + + + + + + + + + +
ExceptionExplanation
SyntaxErrorThe position specified is not a recognised value.
+ +

Visualization of position names

+ +
<!-- beforebegin -->
+<p>
+<!-- afterbegin -->
+foo
+<!-- beforeend -->
+</p>
+<!-- afterend -->
+ +
注意:只有当节点位于树中并具有元素父元素时,beforebegin和afterend位置才能工作。
+ +

范例

+ +
beforeBtn.addEventListener('click', function() {
+  para.insertAdjacentText('afterbegin',textInput.value);
+});
+
+afterBtn.addEventListener('click', function() {
+  para.insertAdjacentText('beforeend',textInput.value);
+});
+ +

Have a look at our insertAdjacentText.html demo on GitHub (see the source code too.) Here we have a simple paragraph. You can enter some text into the form element, then press the Insert before and Insert after buttons to insert it before or after the existing paragraph text using insertAdjacentText(). Note that the existing text node is not added to — further text nodes are created containing the new additions.

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('DOM WHATWG', '#dom-element-insertadjacenttext', 'insertAdjacentText()')}}{{ Spec2('DOM WHATWG') }} 
+ +

浏览器兼容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{ CompatVersionUnknown() }}{{ CompatGeckoDesktop("48.0") }}{{ CompatUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{ CompatUnknown() }}{{ CompatGeckoMobile("48.0") }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+
+ +

也可以看看

+ + -- cgit v1.2.3-54-g00ecf