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

View in English Always switch to English

String.prototype.italics()

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 值的 italics() 方法会创建一个 <i> 元素字符串,其中嵌入了调用的字符串(<i>str</i>),从而使该字符串以斜体显示。

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

语法

js
italics()

参数

无。

返回值

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

示例

使用 italics()

下面的示例使用已弃用的字符串方法来更改字符串的格式:

js
const 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>

规范

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

浏览器兼容性

参见