HTML DOM scripts 集合
定义与用法
scripts 集合返回文档中所有 <script> 元素的集合。
注意: 元素在集合中的排序是它们在源代码中的顺序。
提示: 相关内容 Script 对象。
浏览器支持
表格中的数字表示支持该集合的第一个浏览器的版本号。
| 集合 | |||||
|---|---|---|---|---|---|
| scripts | Yes | Yes | 9.0 | Yes | Yes | 
语法
document.scripts
属性
| 属性 | 描述 | 
|---|---|
| length | 返回集合中 <script> 元素的个数。 提示: 这是一个只读属性。 | 
方法
| 方法 | 描述 | 
|---|---|
| [index] | 返回集合中指定索引(从 0 开始)的  <script> 元素。 注意: 如果索引值超出范围返回 null。 | 
| item(index) | 返回集合中指定索引(从 0 开始)的  <script> 元素。 注意: 如果索引值超出范围返回 null。 | 
| namedItem(id) | 回集合中指定 id 的  <script> 元素。 注意: 如果 id 不存在返回 null。 | 
技术细节
| DOM 版本: | Core Level 3 Document Object | 
|---|---|
| 返回值: | 一个 HTMLCollection 对象, 表示文档中所有的 <script> 元素。集合中元素的排序是根据源码中的顺序排列的。 | 
更多实例
实例
namedItem(id)
获取 id="codexy" 的 <script> 元素的内容:
var x = document.scripts.namedItem("codexy").text;
尝试一下 »
实例
遍历文档中所有的 <script> 元素,并输出每个 <script> 元素的 id:
var x = document.scripts;
var txt = "";
var i;
for (i = 0; i < x.length; i++) {
    txt = txt + x[i].id + "<br>";
}
尝试一下 »
相关文章
JavaScript 参考手册: HTML DOM Script 对象
HTML 教程: HTML 脚本
HTML 参考手册: HTML <script> 标签

 JavaScript 教程
JavaScript 教程 JavaScript 对象
JavaScript 对象 jQuery 教程
jQuery 教程 JSON 教程
JSON 教程 AngularJS 教程
AngularJS 教程 Angular 2 教程
Angular 2 教程 Vue.js 教程
Vue.js 教程 React 教程
React 教程 jQuery UI 教程
jQuery UI 教程 jQuery EasyUI 教程
jQuery EasyUI 教程 AJAX 教程
AJAX 教程 Highcharts 教程
Highcharts 教程 Google Maps API 教程
Google Maps API 教程 ES6 教程
ES6 教程 TypeScript教程
TypeScript教程 ES6 标准入门
ES6 标准入门 Document 对象
 Document 对象