Skip to content

Commit

Permalink
dom
Browse files Browse the repository at this point in the history
  • Loading branch information
houdunwang committed Jun 3, 2020
1 parent e37540b commit 5f18f09
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 0 deletions.
17 changes: 17 additions & 0 deletions video/js/dom/1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>后盾人</title>
</head>
<body>
<!-- 后盾人 -->
<div id="hd"></div>
<h2>houdunren.com</h2>
<script>
let obj = {}
//DOM document object model
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions video/js/dom/2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h2 id="hd">hdcms.com</h2>
<h3 class="hd"></h3>
<h4></h4>
<table>
<tbody>
<tr>
<th>hdcms.com</th>
</tr>
</tbody>
</table>
</body>
<script>
console.log('后盾人')
</script>
</html>
17 changes: 17 additions & 0 deletions video/js/dom/3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>后盾人</title>
</head>
<body>
<script>
// setTimeout(() => {
// let hd = document.getElementById('hd')
// console.log(hd)
// })
</script>
<script src="3.js" defer></script>
<div id="hd"></div>
</body>
</html>
2 changes: 2 additions & 0 deletions video/js/dom/3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let hd = document.getElementById('hd')
console.log(hd)
29 changes: 29 additions & 0 deletions video/js/dom/4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>后盾人</title>
</head>
<body class="red">
<!-- houdunren.com -->
<!-- <script>
console.log(document.nodeType)
console.log(document.body.nodeType)
console.log(document.body.attributes[0].nodeType)
console.log(document.body.childNodes[0].nodeType)
console.log(document.body.childNodes[1].nodeType)
</script> -->
<div id="hd">hdcms.com</div>
<input type="text" id="title" />
<script>
// console.dir(hd)
function prototype(el) {
let p = Object.getPrototypeOf(el)
console.log(p)
Object.getPrototypeOf(p) ? prototype(p) : ''
}
let hd = document.getElementById('title')
prototype(hd)
</script>
</body>
</html>
45 changes: 45 additions & 0 deletions video/js/dom/5.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>后盾人</title>
</head>
<body>
<div id="hd">houdunren.com</div>
<script>
let hd = document.getElementById('hd')
Object.assign(hd, {
id: 'red',
onclick() {
Object.assign(this.style, {
backgroundColor: hd.id,
})
},
})
// Object.assign(hd, {
// color: 'red',
// change() {
// this.innerHTML = '后盾人'
// this.style.color = this.color
// },
// onclick() {
// this.change()
// },
// })
// hd.title = '后盾人'
// hd.id = 'houdunren'
// hd.style.color = 'red'
// hd.name = '后盾人'
// hd.show = function () {
// console.log(this.name)
// }
// hd.show()
// let hd = {}
// hd.name = '后盾人'
// hd.show = function () {
// console.log(this.name)
// }
// hd.show()
</script>
</body>
</html>
32 changes: 32 additions & 0 deletions video/js/dom/6.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>后盾人</title>
</head>
<body>
<div id="app">
<div class="houdunren" data="hd">houdunren.com</div>
<div class="hdcms">hdcms.com</div>
<div class="xiangjun"><!-- 向军大叔 --></div>
</div>
<script>
let app = document.getElementById('app')
console.log(app.nodeType)

console.log(app.firstChild.nodeType)

console.log(app.childNodes[1].attributes[0].nodeType)

const xj = document.querySelector('.xiangjun')
console.log(xj.firstChild.nodeType)

console.dir(app)

console.log(app instanceof HTMLDivElement)

console.log(app instanceof Element)
</script>
</body>
</html>
33 changes: 33 additions & 0 deletions video/js/dom/7.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>后盾人</title>
</head>
<body>
<div id="hd">
<h1>houdunren.com</h1>
<ul>
<li>
<h2>
<span>后盾人</span>
</h2>
</li>
</ul>
</div>
<script>
function all(el) {
const items = []
;[...el.childNodes].map((node) => {
if (node.nodeType == 1) {
items.push(node, ...all(node))
}
})
return items
}
const nodes = all(document.getElementById('hd'))
console.log(nodes)
</script>
</body>
</html>

0 comments on commit 5f18f09

Please sign in to comment.