已废弃
该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。
sup()方法创建 一个<sup>HTML 元素,使字符串显示为上标。
语法
str.sup()
返回值
包含<sup> HTML 元素的字符串。
描述
sup() 方法将字符串嵌入 <sup> 标签中:"<sup>str</sup>".
示例
使用sub()和sup()方法
下面的示例使用了sub()和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>的样子。"
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) String.prototype.sup |
Standard | 初始定义。在 JavaScript 1.0 中实现。在(规范性)附件 B 中定义为用于 Web 浏览器的 ECMAScript 附加特性。 |
| ECMAScript Latest Draft (ECMA-262) String.prototype.sup |
Draft | 在(规范性)附件 B 中定义为用于 Web 浏览器的 ECMAScript 附加特性。 |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains.
Find out how you can help!
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | 1.0 (1.7 or earlier) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | 1.0 (1.0) | (Yes) | (Yes) | (Yes) |