1
<button onclick="myFunction()">点我</button>
2
<p id="demo">单击按钮来检查在文档的第一个列表元素和myList列表第一个元素是否一样。</p>
3
<ul id="myList">
4
<li>Coffee</li>
5
<li>Tea</li>
6
</ul>
7
<script>
8
function myFunction() {
9
var item1 = document.getElementById("myList");
10
var item2 = document.getElementsByTagName("UL")[0];
11
var x = document.getElementById("demo");
12
x.innerHTML = item1.isSameNode(item2);
13
}
14
</script>
15
<p><strong>注意:</strong> Firefox从版本10开始停止支持这种方法,相反,,如果两个节点都是相同的,使用= = =比较</p>
16
<p><strong>注意:</strong> Internet Explorer 8 及之前版本不支持isSame 方法。</p>