XML DOM textContent 属性

定义和用法

textContent 属性设置或返回节点及其后代的文本内容。

当设置时,所有子节点都将被删除并替换为包含此属性值的单个文本节点。

အက္ခရာ

nodeObject.textContent

အမှတ်

လင်္ကပ် 1

အောက်ပါ ကြောင်းရာများ "books.xml" ကို xmlDoc သို့ တင်သွင်းပြီး <book> အပိုင်းအချက်များ အချက်အလက် ကို ပြန်လည်ပေးသည်

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 x, i, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    for(i = 0; i < x.length; i++) {
        txt += x.item(i).textContent + "
"; } document.getElementById("demo").innerHTML = txt; }

亲自试一试

လင်္ကပ် 2

လိုက်နုံး သတင်းချက် အပိုင်း

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 x, i, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    // လိုက်နုံး textContent
    for(i = 0; i < x.length; i++) {
        x.item(i).textContent = "Outdated";
    }
    // 输出 textContent
    for(i = 0; i < x.length; i++) {
        txt += x.item(i).textContent + "
"; } document.getElementById("demo").innerHTML = txt; }

亲自试一试