MediaList: phương thức toString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Phương thức stringifier toString() của giao diện MediaList trả về một chuỗi đại diện cho các giá trị của đối tượng. Giá trị là một danh sách các giá trị media được phân tách bằng dấu phẩy theo cùng định dạng như thuộc tính MediaList.mediaText.

Cú pháp

js
toString()

Tham số

Không có.

Giá trị trả về

Một chuỗi.

Ví dụ

js
const firstStyleSheet = document.styleSheets[0]; // the document's first stylesheet
const mediaList = firstStyleSheet.media; // the mediaList of the stylesheet

// set the `media` text to a media query value
mediaList.mediaText = "SCREEN AND (140PX <= WIDTH <= 380PX)";

// add a second media value
mediaList.appendMedium("SCREEN AND (ORIENTATION: LANDSCAPE))");

// erroneously, add the same media query again
mediaList.appendMedium("SCREEN AND (ORIENTATION: LANDSCAPE))");

console.log(mediaList.toString());
// "screen and (140px <= width <= 380px), screen and (orientation: landscape)"

Thông số kỹ thuật

Thông số kỹ thuật
CSS Object Model (CSSOM)
# MediaList-stringification-behavior

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

Xem thêm