From b3d1ed70cbc7136a6840e9fd4bfeb9f552711b7c Mon Sep 17 00:00:00 2001 From: Jabriel <15688641+jukrb0x@users.noreply.github.com> Date: Tue, 10 Aug 2021 22:26:48 +0800 Subject: Fix mistranslation in Web/JavaScript/Reference/Strict_mode, zh-CN (#1995) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix typo 显示 to 显式 and remove unnecessary space * fix incorrect translation implicitly opting-out: **隐式**地脱离/隐式地退出 - 显示: display - 显式: explicit - 隐式: implicit --- files/zh-cn/web/javascript/reference/strict_mode/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/javascript/reference/strict_mode/index.html b/files/zh-cn/web/javascript/reference/strict_mode/index.html index 4f48146e49..0d9066e644 100644 --- a/files/zh-cn/web/javascript/reference/strict_mode/index.html +++ b/files/zh-cn/web/javascript/reference/strict_mode/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Strict_mode
如果遇到网络故障,{{domxref("GlobalFetch.fetch","fetch()")}} promise 将会 reject,带上一个 {{jsxref("TypeError")}} 对象。虽然这个情况经常是遇到了权限问题或类似问题——比如 404 不是一个网络故障。想要精确的判断 fetch()
是否成功,需要包含 promise resolved 的情况,此时再判断 {{domxref("Response.ok")}} 是不是为 true。类似以下代码:
如果遇到网络故障或服务端的 CORS 配置错误时,{{domxref("GlobalFetch.fetch","fetch()")}} promise 将会 reject,带上一个 {{jsxref("TypeError")}} 对象。虽然这个情况经常是遇到了权限问题或类似问题——比如 404 不是一个网络故障。想要精确的判断 fetch()
是否成功,需要包含 promise resolved 的情况,此时再判断 {{domxref("Response.ok")}} 是不是为 true。类似以下代码:
fetch('flowers.jpg').then(function(response) { if(response.ok) { -- cgit v1.2.3-54-g00ecf From 4420fe37e4677009eb5376d1a64a68945fd7dd8d Mon Sep 17 00:00:00 2001 From: zhyaoangDate: Tue, 10 Aug 2021 22:34:32 +0800 Subject: Update Web/API/Document/execCommand, zh-CN (#2001) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅IE浏览器支持的AutoUrlDetect --- files/zh-cn/web/api/document/execcommand/index.html | 2 ++ 1 file changed, 2 insertions(+) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/api/document/execcommand/index.html b/files/zh-cn/web/api/document/execcommand/index.html index 95624325e6..355a4bd33f 100644 --- a/files/zh-cn/web/api/document/execcommand/index.html +++ b/files/zh-cn/web/api/document/execcommand/index.html @@ -138,6 +138,8 @@ translation_of: Web/API/Document/execCommand 该属性已经废弃,使用 styleWithCSS 代替。 styleWithCSS
用这个取代 useCSS 命令。 参数如预期的那样工作, i.e. true modifies/generates 风格的标记属性, false 生成格式化元素。 ++ AutoUrlDetect
更改浏览器自动链接行为(仅IE浏览器支持) 示例
-- cgit v1.2.3-54-g00ecf From bb34d2a08f28118334cb0d41ce53095db72862e0 Mon Sep 17 00:00:00 2001 From: JJ <307400468@qq.com> Date: Wed, 11 Aug 2021 19:17:27 +0800 Subject: Update files/zh-cn/web/css/vertical-align/index.html (#2015) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原句中「用于垂直对齐一行文本的内的图片」中第一个「的」字应删去 --- files/zh-cn/web/css/vertical-align/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/css/vertical-align/index.html b/files/zh-cn/web/css/vertical-align/index.html index df895fe1cb..eacb94adfc 100644 --- a/files/zh-cn/web/css/vertical-align/index.html +++ b/files/zh-cn/web/css/vertical-align/index.html @@ -18,7 +18,7 @@ translation_of: Web/CSS/vertical-alignvertical-align属性可被用于两种环境:
-
- 使行内元素盒模型与其行内元素容器垂直对齐。例如,用于垂直对齐一行文本的内的图片{{HTMLElement("img")}}:
+- 使行内元素盒模型与其行内元素容器垂直对齐。例如,用于垂直对齐一行文本内的图片{{HTMLElement("img")}}:
-- cgit v1.2.3-54-g00ecf From 9c7081d94a149ed22801e7b7df8ccd2cfbf81225 Mon Sep 17 00:00:00 2001 From: Genitana <24569873+Genitana@users.noreply.github.com> Date: Thu, 12 Aug 2021 12:26:49 +0800 Subject: Update index.html (#2030) make 'timeout' More clear --- files/zh-cn/web/api/window/requestidlecallback/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/api/window/requestidlecallback/index.html b/files/zh-cn/web/api/window/requestidlecallback/index.html index 0632e3a3ce..667133cf18 100644 --- a/files/zh-cn/web/api/window/requestidlecallback/index.html +++ b/files/zh-cn/web/api/window/requestidlecallback/index.html @@ -35,7 +35,7 @@ translation_of: Web/API/Window/requestIdleCallbackoptions
{{optional_inline}}包括可选的配置参数。具有如下属性: -- cgit v1.2.3-54-g00ecf From 013fe2609de0c3ec8745db6574c3be65a9f0046b Mon Sep 17 00:00:00 2001 From: hspn-
- +
timeout
:如果指定了timeout并具有一个正值,并且尚未通过超时毫秒数调用回调,那么回调会在下一次空闲时期被强制执行,尽管这样很可能会对性能造成负面影响。timeout
: 如果指定了timeout,并且有一个正值,而回调在timeout毫秒过后还没有被调用,那么回调任务将放入事件循环中排队,即使这样做有可能对性能产生负面影响。Date: Thu, 12 Aug 2021 12:32:50 +0800 Subject: fixing translation problem (#1870) --- files/zh-cn/web/api/web_workers_api/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/api/web_workers_api/index.html b/files/zh-cn/web/api/web_workers_api/index.html index d9ee40bbaa..ffc27215d7 100644 --- a/files/zh-cn/web/api/web_workers_api/index.html +++ b/files/zh-cn/web/api/web_workers_api/index.html @@ -18,7 +18,7 @@ translation_of: Web/API/Web_Workers_API 使用构造函数(例如,{{domxref("Worker.Worker", "Worker()")}})创建一个 worker 对象, 构造函数接受一个 JavaScript文件URL — 这个文件包含了将在 worker 线程中运行的代码。worker 将运行在与当前 {{domxref("window")}}不同的另一个全局上下文中,这个上下文由一个对象表示,标准情况下为{{domxref("DedicatedWorkerGlobalScope")}} (标准 workers 由单个脚本使用; 共享workers使用{{domxref("SharedWorkerGlobalScope")}})。
-你可以在worker 线程中运行任意的代码,但注意存在一些例外:直接在 worker 线程中操纵 DOM 元素;或使用{{domxref("window")}} 对象中的某些方法和属性。大部分 window 对象的方法和属性是可以使用的,包括 WebSockets,以及诸如 IndexedDB 和 FireFox OS 中独有的 Data Store API 这一类数据存储机制。更多信息请参见: Functions and classes available to workers 。
+你可以在worker 线程中运行任意的代码,但注意存在一些例外:你不能直接在 worker 线程中操纵 DOM 元素;或使用{{domxref("window")}} 对象中的某些方法和属性。大部分 window 对象的方法和属性是可以使用的,包括 WebSockets,以及诸如 IndexedDB 和 FireFox OS 中独有的 Data Store API 这一类数据存储机制。更多信息请参见: Functions and classes available to workers 。
主线程和 worker 线程相互之间使用
-- cgit v1.2.3-54-g00ecf From 90c5bda4bde106ac7bb477393e03c9df85f44406 Mon Sep 17 00:00:00 2001 From: GuanCun <37606400+GuanCun@users.noreply.github.com> Date: Thu, 12 Aug 2021 22:08:48 +0800 Subject: Fix typo in Web/JavaScript/Reference/Global_Objects/encodeURIComponent, zh-CN (#2033) This is a translation error. --- .../javascript/reference/global_objects/encodeuricomponent/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/javascript/reference/global_objects/encodeuricomponent/index.html b/files/zh-cn/web/javascript/reference/global_objects/encodeuricomponent/index.html index be7f03a446..dc3f9a00a2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/encodeuricomponent/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/encodeuricomponent/index.html @@ -89,7 +89,7 @@ console.log(header); function encodeRFC5987ValueChars (str) { return encodeURIComponent(str). - // 注意,仅管 RFC3986 保留 "!",但 RFC5987 并没有 + // 注意,尽管 RFC3986 保留 "!",但 RFC5987 并没有 // 所以我们并不需要过滤它 replace(/['()]/g, escape). // i.e., %27 %28 %29 replace(/\*/g, '%2A'). -- cgit v1.2.3-54-g00ecf From e9170e87569188e45adab3a8d933b155c2165c47 Mon Sep 17 00:00:00 2001 From: meowmeowmeowcatpostMessage()
方法来发送信息, 并且通过onmessage
这个 event handler来接收信息(传递的信息包含在 {{event("Message")}} 这个事件的data
属性内) 。数据的交互方式为传递副本,而不是直接共享数据。Date: Thu, 12 Aug 2021 22:11:06 +0800 Subject: Fix typo in Web/API/Web_Workers_API/Structured_clone_algorithm, zh-CN (#2035) --- .../zh-cn/web/api/web_workers_api/structured_clone_algorithm/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/api/web_workers_api/structured_clone_algorithm/index.html b/files/zh-cn/web/api/web_workers_api/structured_clone_algorithm/index.html index 29bd42fc24..2206042e4b 100644 --- a/files/zh-cn/web/api/web_workers_api/structured_clone_algorithm/index.html +++ b/files/zh-cn/web/api/web_workers_api/structured_clone_algorithm/index.html @@ -14,7 +14,7 @@ original_slug: Web/Guide/API/DOM/The_structured_clone_algorithm
- -
Error
以及Function
对象是不能被结构化克隆算法复制的;如果你尝试这样子去做,这会导致抛出DATA_CLONE_ERR
的异常。- 企图去克隆 DOM 节点同样会抛出
+DATA_CLONE_ERROR
异常。- 企图去克隆 DOM 节点同样会抛出
DATA_CLONE_ERR
异常。- 对象的某些特定参数也不会被保留
- -- cgit v1.2.3-54-g00ecf From daa688a5619e649742d1585a828d1e3a91ef1dbe Mon Sep 17 00:00:00 2001 From: Zjl37 <2693911885@qq.com> Date: Sun, 15 Aug 2021 17:40:45 +0800 Subject: Add Web/Security/Weak_Signature_Algorithm, zh-CN (#1993) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加翻译 Web/Security/Weak_Signature_Algorithm * 将 Web/Security/Weak_Signature_Algorithm 改为 HTML * 将 id 改为英文 --- .../security/weak_signature_algorithm/index.html | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 files/zh-cn/web/security/weak_signature_algorithm/index.html (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/security/weak_signature_algorithm/index.html b/files/zh-cn/web/security/weak_signature_algorithm/index.html new file mode 100644 index 0000000000..1b3963f2ec --- /dev/null +++ b/files/zh-cn/web/security/weak_signature_algorithm/index.html @@ -0,0 +1,32 @@ +--- +title: 弱签名算法 +slug: Web/Security/Weak_Signature_Algorithm +tags: + - Cryptography + - Guide + - Security + - 密码学 + - 指南 + - 安全 +translation_of: Web/Security/Weak_Signature_Algorithm +--- + +
RegExp
对象的lastIndex
字段不会被保留在给{{Glossary("Digital certificate", "数字证书")}}{{Glossary("Signature/Security", "签名")}}时,用到的哈希算法的强度对证书的安全性至关重要。本文将提供一些已知的弱签名算法的信息,以便你在适当的时候避免使用它们。
+ +弱的哈希算法可以使攻击者能够伪造证书。技术进步使网络攻击变得更加可行,随着新型的网络攻击不断被发现,我们不鼓励使用旧的算法,并最终移除了对它们的支持。
+ +SHA-1
+ +从 2017 年开始,主流浏览器不再认为 SHA-1 证书安全。应该使用那些采用更安全的哈希算法(如 SHA-256 或 SHA-512)的证书。
+ +MD5
+ +对基于 MD5 的签名的支持在 2012 年初被移除。
+ +相关资料
+ + + +{{QuickLinksWithSubpages("/zh-CN/docs/Web/Security")}}
\ No newline at end of file -- cgit v1.2.3-54-g00ecf From 5aab2b42a992494838189fc7d302df136519846d Mon Sep 17 00:00:00 2001 From: meowmeowmeowcatDate: Mon, 16 Aug 2021 22:13:32 +0800 Subject: Fix broken live sample (#2060) --- files/zh-cn/web/html/element/input/checkbox/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/html/element/input/checkbox/index.html b/files/zh-cn/web/html/element/input/checkbox/index.html index 14a0d21aef..4f349c2449 100644 --- a/files/zh-cn/web/html/element/input/checkbox/index.html +++ b/files/zh-cn/web/html/element/input/checkbox/index.html @@ -25,7 +25,7 @@ translation_of: Web/HTML/Element/input/checkbox - 指定checkbox处于不定状态(在大多数平台,这样会产生一个划过checkbox的横线)。
-示例
+示例
<p> <input type="checkbox" id="cbox1" value="first_checkbox"> -- cgit v1.2.3-54-g00ecf From 2478646b4648d9c3b98482f186e542fc8ca0cc19 Mon Sep 17 00:00:00 2001 From: IrvinDate: Tue, 17 Aug 2021 02:46:21 +0800 Subject: bring some orphaned docs and relocate according to it's counterpart eng doc (partial revert #1616) (#1618) * Revert "Remove previously orphaned file (#1616)" This reverts commit 49c5601989809c347a5a595e3c5edc08731e5305. * fix broken slugs * rm orphaned docs that eng origin is not available * Web/API/Element/after: sync origin english content --- files/zh-cn/web/api/element/after/index.html | 91 ++++++++++ files/zh-cn/web/api/element/before/index.html | 193 +++++++++++++++++++++ files/zh-cn/web/api/element/remove/index.html | 98 +++++++++++ files/zh-cn/web/api/element/replacewith/index.html | 116 +++++++++++++ files/zh-cn/web/api/renderingcontext/index.html | 30 ++++ 5 files changed, 528 insertions(+) create mode 100644 files/zh-cn/web/api/element/after/index.html create mode 100644 files/zh-cn/web/api/element/before/index.html create mode 100644 files/zh-cn/web/api/element/remove/index.html create mode 100644 files/zh-cn/web/api/element/replacewith/index.html create mode 100644 files/zh-cn/web/api/renderingcontext/index.html (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/api/element/after/index.html b/files/zh-cn/web/api/element/after/index.html new file mode 100644 index 0000000000..ea111ec412 --- /dev/null +++ b/files/zh-cn/web/api/element/after/index.html @@ -0,0 +1,91 @@ +--- +title: Element.after() +slug: Web/API/Element/after +translation_of: Web/API/Element/after +original_slug: Web/API/ChildNode/after +tags: + - API + - DOM + - Method + - Node + - Reference +browser-compat: api.Element.after +--- + {{APIRef("DOM")}}+ ++ +
Element.after()
方法会在其父节点的子节点列表中插入一些 {{domxref("Node")}} 或 {{domxref("DOMString")}} 对象。插入位置为该节点之后。{{domxref("DOMString")}} 对象会被以 {{domxref("Text")}} 的形式插入。语法
+ ++after(... nodes) ++ +参数
+ ++
+ +- +
nodes
- 一组准备插入的 {{domxref("Node")}} 或 {{domxref("DOMString")}} 。
+错误
+ ++
+ +- {{domxref("HierarchyRequestError")}}: 在某些不正确的层级结构进行了插入操作。
+示例
+ +插入元素
+ +let container = document.createElement("div"); +let p = document.createElement("p"); +container.appendChild(p); +let span = document.createElement("span"); + +p.after(span); + +console.log(container.outerHTML); +// "<div><p></p><span></span></div>" ++ +插入文本
+ +let container = document.createElement("div"); +let p = document.createElement("p"); +container.appendChild(p); + +p.after("Text"); + +console.log(container.outerHTML); +// "<div><p></p>Text</div>"+ +同时插入元素和文本
+ +let container = document.createElement("div"); +let p = document.createElement("p"); +container.appendChild(p); +let span = document.createElement("span"); + +p.after(span, "Text"); + +console.log(container.outerHTML); +// "<div><p></p><span></span>Text</div>"+ +规范
+ +{{Specifications}} + +浏览器兼容性
+ +{{Compat}}
+ +相关链接
+ ++
diff --git a/files/zh-cn/web/api/element/before/index.html b/files/zh-cn/web/api/element/before/index.html new file mode 100644 index 0000000000..11553a0194 --- /dev/null +++ b/files/zh-cn/web/api/element/before/index.html @@ -0,0 +1,193 @@ +--- +title: Element.before() +slug: Web/API/Element/before +tags: + - API + - DOM + - Method + - Node + - Reference +translation_of: Web/API/Element/before +original_slug: Web/API/ChildNode/before +browser-compat: api.Element.before +--- +- {{domxref("Element.before()")}}
+- {{domxref("Element.append()")}}
+- {{domxref("Node.appendChild()")}}
+- {{domxref("Element.insertAdjacentElement()")}}
+- {{domxref("NodeList")}}
+{{APIRef("DOM")}} {{SeeCompatTable}}+ ++ +
ChildNode
.before
方法可以在ChildNode这个节点的父节点中插入一些列的
{{domxref("Node")}} 或者 {{domxref("DOMString")}} 对象,位置就是在ChildNode节点的前面,
{{domxref("DOMString")}} 对象其实和 {{domxref("Text")}}节点一样的方式来完成插入的。语法
+ +[Throws, Unscopable] +void Element.before((Node or DOMString)... nodes); ++ +Parameters参数
+ ++
+ +- +
nodes
- 一系列的 {{domxref("Node")}} 或者 {{domxref("DOMString")}}
+Exceptions
+ ++
+ +- {{domxref("HierarchyRequestError")}}: 当节点插入了错误的层级就会出现报错,需要遵循html标签的层级关系,
+Examples事例
+ +Inserting an element插入元素节点
+ +var parent = document.createElement("div"); +var child = document.createElement("p"); +parent.appendChild(child); +var span = document.createElement("span"); + +child.before(span); + +console.log(parent.outerHTML); +// "<div><span></span><p></p></div>" ++ +Inserting text插入文本节点
+ +var parent = document.createElement("div"); +var child = document.createElement("p"); +parent.appendChild(child); + +child.before("Text"); + +console.log(parent.outerHTML); +// "<div>Text<p></p></div>"+ +Inserting an element and text同时插入文本和元素
+ +var parent = document.createElement("div"); +var child = document.createElement("p"); +parent.appendChild(child); +var span = document.createElement("span"); + +child.before(span, "Text"); + +console.log(parent.outerHTML); +// "<div><span></span>Text<p></p></div>"+ ++ +
Element.before()
is unscopable不可使用区域The
+ +before()
不能配合with声明使用,See {{jsxref("Symbol.unscopables")}} for more information.with(node) { + before("foo"); +} +// ReferenceError: before is not defined+ +Polyfill
+ +兼容ie9或者更高版本的方法,You can polyfill the
+ +before() method
in Internet Explorer 9 and higher with the following code:// from: https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/before()/before().md +(function (arr) { + arr.forEach(function (item) { + if (item.hasOwnProperty('before')) { + return; + } + Object.defineProperty(item, 'before', { + configurable: true, + enumerable: true, + writable: true, + value: function before() { + var argArr = Array.prototype.slice.call(arguments), + docFrag = document.createDocumentFragment(); + + argArr.forEach(function (argItem) { + var isNode = argItem instanceof Node; + docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem))); + }); + + this.parentNode.insertBefore(docFrag, this); + } + }); + }); +})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);+ +Specification
+ ++ +
+ ++ +Specification +Status +Comment ++ + +{{SpecName('DOM WHATWG', '#dom-childnode-before', 'Element.before()')}} +{{Spec2('DOM WHATWG')}} +Initial definition. +Browser compatibility
+ +{{CompatibilityTable}}
+ +++ ++ +
++ +Feature +Chrome +Firefox (Gecko) +Internet Explorer +Opera +Safari ++ + +Basic support +{{CompatChrome(54.0)}} +{{CompatGeckoDesktop(49)}} +{{CompatUnknown}} +{{CompatOpera(39)}} +{{CompatUnknown}} +++ ++ +
++ +Feature +Android +Android Webview +Firefox Mobile (Gecko) +IE Mobile +Opera Mobile +Safari Mobile +Chrome for Android ++ + +Basic support +{{CompatNo}} +{{CompatChrome(54.0)}} +{{CompatGeckoMobile(49)}} +{{CompatUnknown}} +{{CompatOpera(39)}} +{{CompatUnknown}} +{{CompatChrome(54.0)}} +See also
+ ++
diff --git a/files/zh-cn/web/api/element/remove/index.html b/files/zh-cn/web/api/element/remove/index.html new file mode 100644 index 0000000000..b244385222 --- /dev/null +++ b/files/zh-cn/web/api/element/remove/index.html @@ -0,0 +1,98 @@ +--- + +title: Element.remove() +slug: Web/API/Element/remove +tags: + - API + - Element + - DOM + - Method +translation_of: Web/API/Element/remove +original_slug: Web/API/ChildNode/remove +browser-compat: api.Element.remove +--- +- {{domxref("ChildNode")}} and {{domxref("ParentNode")}}
+- {{domxref("ChildNode.after()")}}
+- {{domxref("ParentNode.append()")}}
+- {{domxref("Node.appendChild()")}}
+- {{domxref("Node.insertBefore()")}}
+- {{domxref("NodeList")}}
+{{APIRef("DOM")}}
+ ++ +
Element.remove()
方法,把对象从它所属的 DOM 树中删除。语法
+ +node.remove();+ +示例
+ +使用
+ +remove()
<div id="div-01">Here is div-01</div> +<div id="div-02">Here is div-02</div> +<div id="div-03">Here is div-03</div> ++ +var el = document.getElementById('div-02'); +el.remove(); +// id 为 'div-02' 的 div 被删掉了 ++ +{{EmbedLiveSample('使用_remove()')}}
+ ++ +
Element.remove()
是不可见的在
+ +with
语句中,remove()
方法是不可见的。参阅 {{jsxref("Symbol.unscopables")}} 了解更多信息。with(node) { + remove(); +} +// ReferenceError: remove is not defined+ +Polyfill
+ +You can polyfill the
+ +remove()
method in Internet Explorer 9 and higher with the following code://https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md +(function (arr) { + arr.forEach(function (item) { + if (item.hasOwnProperty('remove')) { + return; + } + Object.defineProperty(item, 'remove', { + configurable: true, + enumerable: true, + writable: true, + value: function remove() { + this.parentNode.removeChild(this); + } + }); + }); +})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);+ +规范
+ ++ +
+ ++ +规范 +状态 +注释 ++ + +{{SpecName('DOM WHATWG', '#dom-childnode-remove', 'Element.remove')}} +{{Spec2('DOM WHATWG')}} +Initial definition. +浏览器兼容性
+ + + +{{Compat("api.Element.remove")}}
+ +参见
+ ++
diff --git a/files/zh-cn/web/api/element/replacewith/index.html b/files/zh-cn/web/api/element/replacewith/index.html new file mode 100644 index 0000000000..13fe96c23b --- /dev/null +++ b/files/zh-cn/web/api/element/replacewith/index.html @@ -0,0 +1,116 @@ +--- +title: Element.replaceWith() +slug: Web/API/Element/replaceWith +tags: + - API + - DOM + - Method + - Element + - Reference +browser-compat: api.Element.replaceWith +translation_of: Web/API/Element/replaceWith +original_slug: Web/API/ChildNode/replaceWith +--- +- {{domxref("ChildNode")}} 纯接口。
+- +
+实现此纯接口的对象类型: {{domxref("CharacterData")}}、{{domxref("Element")}} , 和 {{domxref("DocumentType")}}.+{{APIRef("DOM")}} {{SeeCompatTable}}+ ++ +
ChildNode
.replaceWith()
的方法用一套 {{domxref("Node")}} 对象或者 {{domxref("DOMString")}} 对象,替换了该节点父节点下的子节点 。{{domxref("DOMString")}} 对象被当做等效的{{domxref("Text")}} 节点插入。语法
+ +[Throws, Unscopable] +void ChildNode.replaceWith((Node or DOMString)... nodes); ++ +参数
+ ++
+ +- +
节点
- 一系列用来替换的{{domxref("Node")}} 对象或者 {{domxref("DOMString")}} 对象。
+例外
+ ++
+ +- {{domxref("HierarchyRequestError")}}: 无法在层次结构中的指定点插入节点。
+案例
+ +Using
+ +replaceWith()
var parent = document.createElement("div"); +var child = document.createElement("p"); +parent.appendChild(child); +var span = document.createElement("span"); + +child.replaceWith(span); + +console.log(parent.outerHTML); +// "<div><span></span></div>" ++ ++ +
ChildNode.replaceWith()
is unscopable+ +
replaceWith()
的方法并没有作用于with语句. 参考 {{jsxref("Symbol.unscopables")}} 获取更多信息.with(node) { + replaceWith("foo"); +} +// ReferenceError: replaceWith is not defined+ +Polyfill
+ +你可以在IE9及更高级的浏览器中使用下面的代码向上兼容
+ +replaceWith()
的方法:(function (arr) { + arr.forEach(function (item) { + if (item.hasOwnProperty('replaceWith')) { + return; + } + Object.defineProperty(item, 'replaceWith', { + configurable: true, + enumerable: true, + writable: true, + value: function replaceWith() { + var argArr = Array.prototype.slice.call(arguments), + docFrag = document.createDocumentFragment(); + + argArr.forEach(function (argItem) { + var isNode = argItem instanceof Node; + docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem))); + }); + + this.parentNode.replaceChild(docFrag, this); + } + }); + }); +})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);+ +规范
+ ++ +
+ ++ +规范 +状态 +注释 ++ + +{{SpecName('DOM WHATWG', '#dom-childnode-replacewith', 'ChildNode.replacewith()')}} +{{Spec2('DOM WHATWG')}} +Initial definition. +浏览器兼容性
+ +{{Compat("api.ChildNode.replaceWith")}}
+ +参阅
+ ++
diff --git a/files/zh-cn/web/api/renderingcontext/index.html b/files/zh-cn/web/api/renderingcontext/index.html new file mode 100644 index 0000000000..4cf1dfc0b7 --- /dev/null +++ b/files/zh-cn/web/api/renderingcontext/index.html @@ -0,0 +1,30 @@ +--- +title: RenderingContext +slug: Web/API/RenderingContext +translation_of: Web/API/RenderingContext +original_slug: Web/API/RenderingContext +--- +- {{domxref("ChildNode")}} 和 {{domxref("ParentNode")}}
+- {{domxref("Node.replaceChild()")}}
+- {{domxref("NodeList")}}
+{{APIRef("Canvas API")}}
+ ++ +
RenderingContext
是一个辅助类型,描述下面任何一个渲染上下文: {{domxref("CanvasRenderingContext2D")}}, {{domxref("WebGLRenderingContext")}} 或者 {{domxref("WebGL2RenderingContext")}} (继承自WebGLRenderingContext
)。这是简化规范的辅助类型,它不是一个接口,也没有对象实现它。
+ +规范描述
+ ++ +
+ ++ +Specification +Status +Comment ++ + +{{SpecName('HTML WHATWG', "scripting.html#renderingcontext", "RenderingContext")}} +{{Spec2('HTML WHATWG')}} +Initial definition. +\ No newline at end of file -- cgit v1.2.3-54-g00ecf