--- title: Document.scripts slug: Web/API/Document/scripts translation_of: Web/API/Document/scripts ---

{{ ApiRef() }}

概述

返回一个{{ domxref("HTMLCollection") }}对象,包含了当前文档中所有{{ HTMLElement("script") }}元素的集合.

语法

var scriptList = document.scripts;

scriptList是一个{{ domxref("HTMLCollection") }}对象.你可以像使用数组一样通过索引来获取其中包含的{{ HTMLElement("script") }}元素.

例子

下例演示了如何查看当前页面是否包含有{{ HTMLElement("script") }}元素.

var scripts = document.scripts;

if (scripts.length) {
  alert("该页面存在script标签!");
}

浏览器兼容性

{{ CompatibilityTable() }}

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

规范

{{ spec("http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-scripts", "DOM: document scripts") }}

{{ languages( {"en": "en/DOM/Document.scripts" } ) }}