String.prototype.small()

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

String 值的 small() 方法创建一个 <small> 元素字符串,其中嵌入了调用的字符串(<small>str</small>),从而使该字符串以小号字体显示。

备注: 所有 HTML 包装方法都已被弃用,并且仅为了兼容性而标准化。请使用 DOM API(例如 document.createElement())代替。

语法

js
small()

参数

无。

返回值

一个以 <small> 开始标签开头的字符串,接着是文本 str,最后是 </small> 结束标签。

示例

使用 small()

以下示例使用字符串方法更改字符串的大小:

js
const worldString = "Hello, world";

console.log(worldString.small()); // <small>Hello, world</small>
console.log(worldString.big()); // <big>Hello, world</big>
console.log(worldString.fontsize(7)); // <font size="7">Hello, world</fontsize>

使用 element.style 对象,你可以获取元素的 style 属性并以更通用的方式进行操作,例如:

js
document.getElementById("yourElemId").style.fontSize = "0.7em";

规范

Specification
ECMAScript® 2025 Language Specification
# sec-string.prototype.small

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
small
Deprecated

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Deprecated. Not for use in new websites.

参见