概述

返回一个HTMLCollection对象,包含了当前文档中所有<script>元素的集合.

语法

var scriptList = document.scripts;

scriptList是一个HTMLCollection对象.你可以像使用数组一样通过索引来获取其中包含的<script>元素.

例子

下例演示了如何查看当前页面是否包含有<script>元素.

var scripts = document.scripts;

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

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 9.0 (9.0) (Yes) (Yes) (Yes)
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 9.0 (9.0) (Yes) (Yes) (Yes)

规范

DOM: document scripts

文档标签和贡献者

此页面的贡献者: teoli, jsx, AlexChao, ziyunfei
最后编辑者: jsx,