blob: d02f838d8c918628844de763a1311bad3dd2ff15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
---
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>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatGeckoDesktop("9.0") }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatGeckoMobile("9.0") }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
</tr>
</tbody>
</table>
</div>
<h3 id="Specification" name="Specification">规范</h3>
<p>{{ spec("http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-scripts", "DOM: document scripts") }}</p>
<p>{{ languages( {"en": "en/DOM/Document.scripts" } ) }}</p>
|