String.prototype.italics()

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Phương thức italics() của các giá trị String tạo ra một chuỗi nhúng chuỗi này vào trong phần tử <i> (<i>str</i>), khiến chuỗi này được hiển thị in nghiêng.

Note: Tất cả các phương thức bọc HTML đều đã bị deprecated và chỉ được chuẩn hóa cho mục đích tương thích. Hãy sử dụng DOM APIs như document.createElement() thay thế.

Cú pháp

js
italics()

Tham số

Không có.

Giá trị trả về

Một chuỗi bắt đầu bằng thẻ mở <i>, sau đó là văn bản str, và cuối cùng là thẻ đóng </i>.

Ví dụ

Sử dụng italics()

Đoạn code dưới đây tạo ra một chuỗi HTML rồi thay thế nội dung body của document bằng chuỗi đó:

js
const contentString = "Hello, world";

document.body.innerHTML = contentString.italics();

Đoạn code này sẽ tạo ra HTML sau:

html
<i>Hello, world</i>

Thay vì sử dụng italics() và tạo văn bản HTML trực tiếp, bạn nên sử dụng DOM APIs như document.createElement(). Ví dụ:

js
const contentString = "Hello, world";
const elem = document.createElement("i");
elem.innerText = contentString;
document.body.appendChild(elem);

Đặc tả

Thông số kỹ thuật
ECMAScript® 2027 Language Specification
# sec-string.prototype.italics

Tương thích trình duyệt

Xem thêm