From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/global_objects/string/sub/index.html | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/sub/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/string/sub') diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/sub/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/sub/index.html new file mode 100644 index 0000000000..8c47471d25 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/string/sub/index.html @@ -0,0 +1,119 @@ +--- +title: String.prototype.sub() +slug: Web/JavaScript/Reference/Global_Objects/String/sub +tags: + - String.sub() + - 已废弃 +translation_of: Web/JavaScript/Reference/Global_Objects/String/sub +--- +
{{JSRef}} {{deprecated_header}}
+ +

sub()方法创建一个 {{HTMLElement("sub")}} HTML 元素,使字符串展示为下标。

+ +

语法

+ +
str.sub()
+ +

返回值

+ +

包含{{HTMLElement("sub")}} HTML 元素的字符串。

+ +

描述

+ +

sub()方法将字符串嵌入<sub>标签: "<sub>str</sub>".

+ +

示例

+ +

使用sub()sup()方法

+ +

下面的示例使用了sub()和{{jsxref("String.prototype.sup()", "sup()")}}方法来格式化字符串:

+ +
var superText = 'superscript';
+var subText = 'subscript';
+
+console.log('This is what a ' + superText.sup() + ' looks like.');
+// 这就是<sup>superscript</sup>的样子。
+
+console.log('This is what a ' + subText.sub() + ' looks like.');
+// 这就是<sub>subscript</sub>的样子。
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-string.prototype.sub', 'String.prototype.sub')}}{{Spec2('ES6')}}初始定义。在 JavaScript 1.0 中实现。在(规范性)附件 B 中定义为用于 Web 浏览器的 ECMAScript 附加特性。
{{SpecName('ESDraft', '#sec-string.prototype.sub', 'String.prototype.sub')}}{{Spec2('ESDraft')}}在(规范性)附件 B 中定义为用于 Web 浏览器的 ECMAScript 附加特性。
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

另见

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