XML DOM isSameNode() Method

Definition and Usage

isSameNode() This method tests whether two nodes are the same.

Hint:Use the isEqualNode() method to determine if two nodes are equal.

Syntax

nodeObject.isSameNode(nodetocheck)

Parameters

Parameters Description
nodetocheck Required. Node object. The node to be compared with the current node.

Technical Details

Return value: Boolean value. Returns true if two nodes are the same, otherwise false.
Δημιουργία DOM: Core Level 3 Node Object

Παράδειγμα

η κώδικας που ακολουθεί θα φορτώσει το "books.xml" στο xmlDoc και θα ελέγξει αν δύο κόμβοι είναι ο ίδιος:

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')[1];
    var y = xmlDoc.getElementsByTagName('book')[1];
    document.getElementById("demo").innerHTML =
    x.isSameNode(y);
}

亲自试一试

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持

所有主流浏览器都支持 isSameNode() 方法。

注释:Internet Explorer 9 及更早版本不支持此方法。