-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15.JS_DOM.html
32 lines (30 loc) · 1.02 KB
/
15.JS_DOM.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM</title>
</head>
<body>
<div id="box1">这是一个ID选择器标签</div>
<div class="box2">这是一个类选择器标签</div>
<div>普通div选择器</div>
<button>按钮</button>
<script>
var a = document.getElementById('box1')
var b = document.getElementsByClassName('box2')[0]
var c = document.getElementsByTagName('div')[2]
console.log(a)
a.innerHTML = '修改ID选择器标签的文本内容'
b.innerText = '修改后的类标签文本内容'
c.style.color = 'red'
c.style.fontSize = '30px'
//DOM属性绑定事件
var button_element = document.getElementsByTagName('button')[0]
console.log(button_element)
button_element.onclick = function(){
alert('DOM属性按键触发')
}
</script>
</body>
</html>