-
Notifications
You must be signed in to change notification settings - Fork 1
/
defineProperty.html
42 lines (38 loc) · 1013 Bytes
/
defineProperty.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</style>
</head>
<body>
<!-- 三角形 -->
<div class="demo1">
<input id="input" type="text">
<p id="dom"></p>
</div>
<script>
const inputDom = document.getElementById('input')
const pDom = document.getElementById('dom')
// inputDom.addEventListener('input',(e)=>{
// console.log(e);
// pDom.innerText = e.target.value
// })
const obj = {}
let key =''
Object.defineProperty(obj,'key',{
set(newValue){
if(newValue === obj.key) return
pDom.innerText = newValue
},
get(){
console.log(111);
return key
}
})
inputDom.addEventListener('input',e=>{
obj.key = e.target.value
})
</script>
</body>
</html>