JavaScript 參考手冊
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="json" 的 <script> 元素的內容:
遍歷文檔中所有的 <script> 元素,并輸出每個 <script> 元素的 id:
JavaScript 參考手冊: HTML DOM Script 對象
HTML 教程: HTML 腳本
HTML 參考手冊: HTML <script> 標簽