Metodo hasChildNodes() di XML DOM
Definizione e uso
Se il nodo specificato ha eventuali nodi figli, allora hasChildNodes()
Il metodo restituisce true, altrimenti restituisce false.
Sintassi
nodeObject.hasChildNodes()
Parametro
Nessuno.
Dettagli tecnici
Versione DOM: | Oggetto Node di Livello di Core 1 |
---|---|
Valore di ritorno: | Valore booleano. Restituisce true se il nodo specificato ha nodi figli, altrimenti restituisce false. |
Esempio
Il codice seguente carica "books.xml" nel xmlDoc e restituisce se il primo elemento <book> ha eventuali nodi figli:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); function myFunction(xml) { var xmlDoc = xml.responseXML; var x = xmlDoc.getElementsByTagName('book')[0]; document.getElementById("demo").innerHTML = x.hasChildNodes(); }
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 支持 | 支持 | 支持 | 支持 |
所有主流浏览器都支持 hasChildNodes()
方法。