blob: 28ee08298aa82d531ec48b3c373883f37d6281f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
---
title: Document.scripts
slug: Web/API/Document/scripts
translation_of: Web/API/Document/scripts
---
<p>{{ ApiRef() }}</p>
<h3 id="Summary" name="Summary">概述</h3>
<p>返回一个{{ domxref("HTMLCollection") }}对象,包含了当前文档中所有{{ HTMLElement("script") }}元素的集合.</p>
<h3 id="Syntax" name="Syntax">语法</h3>
<pre class="eval"><code>var <em>scriptList</em></code> = document.scripts;
</pre>
<p><code>scriptList是一个</code>{{ domxref("HTMLCollection") }}对象.你可以像使用数组一样通过索引来获取其中包含的{{ HTMLElement("script") }}元素.</p>
<h3 id="例子">例子</h3>
<p>下例演示了如何查看当前页面是否包含有{{ HTMLElement("script") }}元素.</p>
<pre class="brush: js">var scripts = document.scripts;
if (scripts.length) {
alert("该页面存在script标签!");
}
</pre>
<h3 id="Specification" name="Specification">浏览器兼容性</h3>
{{Compat("api.Document.scripts")}}
|