XML DOM isSameNode() Method

Definition and Usage

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

Tips: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 the two nodes are the same, otherwise returns false.
DOM Version: Core Level 3 Node Object

Mga Halimbawa

Ang mga sumusunod na kodigo ay maglalaad ng "books.xml" sa xmlDoc at susubukang pagtetest kung ang dalawang node ay parehong node:

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 及更早版本不支持此方法。