<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</title>
</head>
<body>
<button onclick="myFunction()">点我</button>
<p id="demo">单击按钮来检查在文档的第一个列表元素和myList列表第一个元素是否一样。</p>
<ul id="myList"><li>Coffee</li><li>Tea</li></ul>
<script>
function myFunction(){
var item1=document.getElementById("myList");
var item2=document.getElementsByTagName("UL")[0];
var x=document.getElementById("demo");
x.innerHTML=item1.isSameNode(item2);
}
</script>
<p><strong>注意:</strong> Firefox从版本10开始停止支持这种方法,相反,,如果两个节点都是相同的,使用= = =比较</p>
<p><strong>注意:</strong> Internet Explorer 8 及之前版本不支持isSame 方法。</p>
</body>
</html>