中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

HTML DOM scripts 集合

Document 對象參考手冊 Document 對象

實例

查看文檔中有多少個 <script> 元素:

var x = document.scripts.length;

運行代碼 ?

定義與用法

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。

技術細節(jié)

DOM 版本: Core Level 3 Document Object
返回值: 一個 HTMLCollection 對象, 表示文檔中所有的 <script> 元素。集合中元素的排序是根據源碼中的順序排列的。

更多實例

實例

[index]

獲取文檔中第一個(索引為 0) <script> 元素的內容:

var x = document.scripts[0].text;

運行代碼 ?

實例

item(index)

獲取文檔中第一個(索引為 0) <script> 元素的內容:

var x = document.scripts.item(0).text;

運行代碼 ?

實例

namedItem(id)

獲取 id="json" 的 <script> 元素的內容:

var x = document.scripts.namedItem("json").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> 標簽


Document 對象參考手冊 Document 對象

其他擴展