HTML DOM Belgesi komut dosyaları
Örnekler
Belgedeki <script> öğelerinin sayısı:
document.scripts.length;
İlk <script> öğesinin içeriğini döndürün:
document.scripts[0].text;
İlk <script> öğesinin içeriğini döndürün:
document.scripts.item(0).text;
Aşağıda daha fazla örnek.
Tanım ve Kullanım
Özellik scripts
, belgedeki tüm <script> öğelerinin bir koleksiyonunu döndürür.
Özellik scripts
, bir HTMLCollection döndürür .
scripts
Mülk salt okunurdur .
Ayrıca bakınız:
HTML Koleksiyonu
HTMLCollection , HTML düğümlerinin bir koleksiyonudur .
Bir koleksiyondaki düğümlere dizin numaralarıyla erişilebilir. Endeks 0'dan başlar.
Uzunluk Özelliği , koleksiyondaki öğelerin sayısını döndürür.
Sözdizimi
document.scripts
Özellikler
Mülk | Açıklama |
uzunluk | Koleksiyondaki <script> öğelerinin sayısı. |
yöntemler
Method | Description |
[index] | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
item(index) | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
namedItem(id) | Returns the element with the specified id. Returns null if the id does not exist. |
Geri dönüş değeri
Tip | Açıklama |
Nesne | Bir HTMLCollection Nesnesi. Belgedeki tüm <script> öğeleri. Öğeler, belgede göründükleri gibi sıralanır. |
Daha fazla örnek
<script> öğesinin içeriğini id="myScript" ile döndürün:
document.scripts.namedItem("myScript").text;
Tüm <script> öğeleri üzerinde dolaşın ve her bir kimliği çıktılayın:
const collection = document.scripts;
let text = "";
for (let i = 0; i < collection.length; i++) {
text += collection[i].id + "<br>";
}
Tarayıcı Desteği
document.scripts
bir DOM Düzey 2 (2001) özelliğidir.
Tüm tarayıcılarda tam olarak desteklenir:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |