<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # XML DOM 替換節點 replaceChild() 方法替換指定節點。 nodeValue 屬性替換文本節點中的文本。 ## 嘗試一下 - 實例 下面的實例使用 XML 文件 [books.xml](images/books.xml)。 函數 [loadXMLDoc()](dom-loadxmldoc.html),位于外部 JavaScript 中,用于加載 XML 文件。 [替換元素節點](/try/try.php?filename=try_dom_replacechild) 本例使用 replaceChild() 來替換第一個 &lt;book&gt; 節點。 ``` <!DOCTYPE html> <html> <head> <script src="loadxmldoc.js"> </script> </head> <body> <script> xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.documentElement; //create a book element, title element and a text node newNode=xmlDoc.createElement("book"); newTitle=xmlDoc.createElement("title"); newText=xmlDoc.createTextNode("A Notebook"); //add the text node to the title node, newTitle.appendChild(newText); //add the title node to the book node newNode.appendChild(newTitle); y=xmlDoc.getElementsByTagName("book")[0] //replace the first book node with the new node x.replaceChild(newNode,y); z=xmlDoc.getElementsByTagName("title"); for (i=0;i<z.length;i++) { document.write(z[i].childNodes[0].nodeValue); document.write("<br>"); } </script> </body> </html> ``` [替換文本節點中的數據](/try/try.php?filename=try_dom_replacedata2) 本例使用 nodeValue 屬性來替換文本節點中的數據。 ``` <!DOCTYPE html> <html> <head> <script src="loadxmldoc.js"> </script> </head> <body> <script> xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName("title")[0].childNodes[0]; document.write(x.nodeValue); x.nodeValue="Easy Italian"; document.write("<br>"); document.write(x.nodeValue); </script> </body> </html> ``` ## 替換元素節點 replaceChild() 方法用于替換節點。 下面的代碼片段替換第一個 &lt;book&gt; 元素: ## 實例 ``` xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.documentElement; //create a book element, title element and a text node newNode=xmlDoc.createElement("book"); newTitle=xmlDoc.createElement("title"); newText=xmlDoc.createTextNode("A Notebook"); //add the text node to the title node, newTitle.appendChild(newText); //add the title node to the book node newNode.appendChild(newTitle); y=xmlDoc.getElementsByTagName("book")[0] //replace the first book node with the new node x.replaceChild(newNode,y); ``` 實例解釋: 1. 使用 [loadXMLDoc()](dom-loadxmldoc.html) 把 "[books.xml](images/books.xml)" 載入 xmlDoc 中 2. 創建一個新的元素節點 &lt;book&gt; 3. 創建一個新的元素節點 &lt;title&gt; 4. 創建一個新的文本節點,帶有文本 "A Notebook" 5. 向新元素節點 &lt;title&gt; 追加這個新文本節點 6. 向新元素節點 &lt;book&gt; 追加這個新元素節點 &lt;title&gt; 7. 把第一個 &lt;book&gt; 元素節點替換為新的 &lt;book&gt; 元素節點 ## 替換文本節點中的數據 replaceData() 方法用于替換文本節點中的數據。 replaceData() 方法有三個參數: * offset - 在何處開始替換字符。offset 值以 0 開始。 * length - 要替換多少字符 * string - 要插入的字符串 ## 實例 ``` xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName("title")[0].childNodes[0]; x.replaceData(0,8,"Easy"); ``` 實例解釋: 1. 使用 [loadXMLDoc()](dom-loadxmldoc.html) 把 "[books.xml](images/books.xml)" 載入 xmlDoc 中 2. 獲取第一個 &lt;title&gt; 元素節點的文本節點 3. 使用 replaceData 方法把文本節點的前 8 個字符替換為 "Easy" ## 使用 nodeValue 屬性代替 用 nodeValue 屬性來替換文本節點中數據會更加容易。 下面的代碼片段將用 "Easy Italian" 替換第一個 &lt;title&gt; 元素中的文本節點值: ## 實例 ``` xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName("title")[0].childNodes[0]; x.nodeValue="Easy Italian"; ``` 實例解釋: 1. 使用 [loadXMLDoc()](dom-loadxmldoc.html) 把 "[books.xml](images/books.xml)" 載入 xmlDoc 中 2. 獲取第一個 &lt;title&gt; 元素節點的文本節點 3. 使用 nodeValue 屬性來更改這個文本節點的文本 您可以在[改變節點](dom-nodes-set.html)這一章中閱讀更多有關更改節點值的內容。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看