mediaText 特性为 MediaList interface is a stringifier that returns a DOMString 表示 MediaList as text, and also allows you to set a new MediaList .

句法

mediaListInstance.mediaText;
mediaListInstance.mediaText = string;
					

A DOMString representing the media queries of a stylesheet. Each one is separated by a comma, for example screen and (min-width: 480px), print .

If you wish to set new media queries on the document, the string value must have the different queries separated by commas, e.g. screen, print 。注意, MediaList is a live list; updating the list via mediaText will immediately update the behavior of the document.

Also note that is you try to set mediaText to null , it will be treated as an empty string, i.e. the value will be set to "" .

范例

The following would log to the console a textual representation of the MediaList of the first stylesheet applied to the current document.

const stylesheets = document.styleSheets;
let stylesheet = stylesheets[0];
console.log(stylesheet.media.mediaText);
					

规范

规范 状态 注释
CSS Object Model (CSSOM)
The definition of 'mediaText' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
mediaText Chrome Yes Edge ≤18 Firefox Yes IE ? Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改: