Gli ultimi tutorial di sviluppo web
 

XML DOM appendData() Method


<Oggetto Commento

Esempio

I seguenti frammento di codice carichi " books_comment.xml " in xmlDoc e aggiunge il testo al primo elemento commento:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
myFunction(xhttp);
}
};
xhttp.open("GET", "books_comment.xml", true);
xhttp.send();

function myFunction(xml) {
    var x, i, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName("book")[0].childNodes;
    for (i = 0; i < x.length; i++) {
    // Process only comment nodes
        if (x[i].nodeType == 8) {
            x[i].appendData(" Special Offer");
            txt += x[i].data + "<br>";
        }
    }
    document.getElementById("demo").innerHTML = txt;
}

Produzione:

125 Simple and Delicious Recipes (Hardcover) Special Offer
Prova tu stesso "

Nel precedente esempio usiamo un ciclo e un se-test per assicurarsi che solo i processi di commento nodi. Un nodo commento ha un tipo di nodo di 8.


Definizione e utilizzo

Il appendData() metodo aggiunge dati al termine di un nodo di commenti.

Sintassi

commentNode.appedData(string)
Parametro Descrizione
string Richiesto. La stringa da aggiungere al nodo commento

<Oggetto Commento