JavaScript 參考手冊(cè)
scripts 集合返回文檔中所有 <script> 元素的集合。
注意: 元素在集合中的排序是它們?cè)谠创a中的順序。
提示: 相關(guān)內(nèi)容 Script 對(duì)象。
表格中的數(shù)字表示支持該集合的第一個(gè)瀏覽器的版本號(hào)。
集合 | |||||
---|---|---|---|---|---|
scripts | Yes | Yes | 9.0? | Yes | Yes |
document.scripts
屬性 | 描述 |
---|---|
length | 返回集合中 <script> 元素的個(gè)數(shù)。 提示: 這是一個(gè)只讀屬性。 |
方法 | 描述 |
---|---|
[index] | 返回集合中指定索引(從 0 開始)的 <script> 元素。 注意: 如果索引值超出范圍返回 null。 |
item(index) | 返回集合中指定索引(從 0 開始)的 <script> 元素。 注意: 如果索引值超出范圍返回 null。 |
namedItem(id) | 回集合中指定 id 的 <script> 元素。 注意: 如果 id 不存在返回 null。 |
DOM 版本: | Core Level 3 Document Object |
---|---|
返回值: | 一個(gè) HTMLCollection 對(duì)象, 表示文檔中所有的 <script> 元素。集合中元素的排序是根據(jù)源碼中的順序排列的。 |
[index]
獲取文檔中第一個(gè)(索引為 0) <script> 元素的內(nèi)容:
item(index)
獲取文檔中第一個(gè)(索引為 0) <script> 元素的內(nèi)容:
namedItem(id)
獲取 id="json" 的 <script> 元素的內(nèi)容:
遍歷文檔中所有的 <script> 元素,并輸出每個(gè) <script> 元素的 id:
JavaScript 參考手冊(cè): HTML DOM Script 對(duì)象
HTML 教程: HTML 腳本
HTML 參考手冊(cè): HTML <script> 標(biāo)簽