此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

String.prototype.sup()

Deprecated

Avoid using this feature in new projects. HTML wrapper methods exist only for backwards compatibility. Use DOM APIs to create elements instead. This feature may be a candidate for removal from web standards or browsers.

Consider using the following features instead: DOM.

String 值的 sup() 方法创建一个 <sup> 元素字符串,其中嵌入了调用的字符串(<sup>str</sup>)中,这会导致该字符串显示为上标。

备注:所有 HTML 包装器方法 均已弃用,仅出于兼容性目的而进行标准化。请改用 DOM API,例如 document.createElement()

语法

js
sup()

参数

无。

返回值

<sup> 开始标记开头的字符串,然后是文本 str,最后是 </sup> 结束标记。

示例

使用 sub() 和 sup() 方法

下面的示例使用了 sub()sup() 方法来格式化字符串:

js
const superText = "上标";
const subText = "下标";

console.log(`这就是${superText.sup()}的样子。`);
// "这就是<sup>上标</sup>的样子。"

console.log(`这就是${subText.sub()}的样子。`);
// "这就是<sub>下标</sub>的样子。"

规范

规范
ECMAScript® 2027 Language Specification
# sec-string.prototype.sup

浏览器兼容性

参见