--- title: String.prototype.bold() slug: Web/JavaScript/Reference/Global_Objects/String/bold tags: - Deprecated - HTML wrapper methods - JavaScript translation_of: Web/JavaScript/Reference/Global_Objects/String/bold ---

{{JSRef}} {{deprecated_header}}

bold() 方法会创建 HTML 元素 “b”,并将字符串加粗展示。

语法

str.bold()

返回值

包含HTML元素 {{HTMLElement("b")}} 的字符串。

描述

bold() 方法将一个字符串嵌入到<b></b>标记中。

示例

使用bold()

下面的例子使用字符串方法来改变字符串的格式。

var worldString = 'Hello, world';

console.log(worldString.blink());   // <blink>Hello, world</blink>
console.log(worldString.bold());    // <b>Hello, world</b>
console.log(worldString.italics()); // <i>Hello, world</i>
console.log(worldString.strike());  // <strike>Hello, world</strike>

规范

Specification Status Comment
{{SpecName('ES6', '#sec-string.prototype.bold', 'String.prototype.bold')}} {{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.bold', 'String.prototype.bold')}} {{Spec2('ESDraft')}} Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers.

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatGeckoDesktop("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

相关连接