--- title: String.prototype.fixed() slug: Web/JavaScript/Reference/Global_Objects/String/fixed tags: - Deprecated - HTML wrapper methods - JavaScript translation_of: Web/JavaScript/Reference/Global_Objects/String/fixed ---
fixed()方法创建了一个<tt>标签元素将字符串包裹起来,从而让这个字符串里面的内容具有固定间距。
str.fixed()
返回一个表示 {{HTMLElement("tt")}} HTML 元素的字符串。
fixed()
方法将一个字符串包裹在<tt></tt>标签中,比如: "<tt>str</tt>"
.
下面的示例代码使用这个fixed方法来改变字符串的格式:
var worldString = 'Hello, world'; console.log(worldString.fixed()); // "<tt>Hello, world</tt>"
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-string.prototype.fixed', 'String.prototype.fixed')}} | {{Spec2('ES6')}} | Initial definition. Implemented in JavaScript 1.0. Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
{{SpecName('ESDraft', '#sec-string.prototype.fixed', 'String.prototype.fixed')}} | {{Spec2('ESDraft')}} | Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
版本 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
版本 | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |