String.prototype.fixed()
Deprecated
String 值的 fixed() 方法创建一个 <tt> 元素字符串,其中嵌入了调用的字符串(<tt>str</tt>),这会导致该字符串以等宽字体显示。
备注:所有 HTML 包装方法都已被弃用,并且仅为了兼容性而标准化。请使用 DOM API(例如 document.createElement())代替。
语法
js
fixed()
参数
无。
返回值
一个以 <tt> 开始标签开头的字符串,接着是文本 str,然后是 </tt> 结束标签。
示例
>使用 fixed()
以下示例使用 fixed 方法来更改字符串的格式:
js
const worldString = "Hello, world";
console.log(worldString.fixed()); // "<tt>Hello, world</tt>"
规范
| 规范 |
|---|
| ECMAScript® 2027 Language Specification> # sec-string.prototype.fixed> |