js.ownerDocument 返回某元素的根元素

113 阅读1分钟

HTML中, HTML 文档本身是元素的根元素 返回的都是html, 并没什么用

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta http-equiv="Cache-Control" CONTENT="no-cache" />
		<meta http-equiv="Pragma" CONTENT="no-cache" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>js.ownerDocument 返回某元素的根元素</title>
	</head>

	<body>

		<div id="id1">id1</div>
		<div id="id2">id2</div>

	</body>

	<script type="text/javascript" th:inline="javascript">
		"use strict";

		console.log(document.getElementById("id1").ownerDocument)

		console.log(document.getElementById("id1").ownerDocument === document.getElementById("id2").ownerDocument)
	</script>

</html>

end