abstract:<!DOCTYPE html><html><head> <title>DOM</title></head><body><p class="class1" id="id1">class1 這是一個P標(biāo)簽 id1</p><p class="
<!DOCTYPE html>
<html>
<head>
<title>DOM</title>
</head>
<body>
<p class="class1" id="id1">class1 這是一個P標(biāo)簽 id1</p>
<p class="class2" id="id2">class2 這是一個P標(biāo)簽 id2</p>
<a href="www.baidu.com" name="na">www.baidu.com</a>
<form action="" name="na">
<input type="text" name="username">
<input type="password" name="password">
<button name="button">提交</button>
</form>
<div onclick="function_id()">點(diǎn)擊對id1進(jìn)行backgroundColor='red'操作</div>
<div onclick="function_n()">點(diǎn)擊對name進(jìn)行backgroundColor='yellow'操作</div>
<div onclick="function_tag()">點(diǎn)擊對p標(biāo)簽進(jìn)行backgroundColor='blue'操作</div>
<div onclick="function_form0()">點(diǎn)擊對forms[0]標(biāo)簽進(jìn)行backgroundColor='lightgreen'操作</div>
<div onclick="function_link()">點(diǎn)擊對links[0].style.backgroundColor=#505050操作</div>
<div onclick="function_link1()">點(diǎn)擊對links['na'].style.backgroundColor='#900000'操作</div>
<div onclick="function_link2()">點(diǎn)擊對links.na.style.backgroundColor='#800000'操作</div>
<div onclick="function_link3()">點(diǎn)擊對links.item(0).style.backgroundColor='#100000'操作</div>
<script type="text/javascript">
function function_id() {
document.getElementById('id1').style.backgroundColor='red'
console.log(document.getElementById('id1'))
}
function function_n(){
document.na.style.backgroundColor='yellow'
}
function function_tag(){
let a = document.getElementsByTagName('p')
for (let i=0;i<a.length;i++){
document.getElementsByTagName('p')[i].style.backgroundColor='blue'
}
}
function function_form0(){
document.forms[0].style.backgroundColor='lightgreen'
}
function function_link(){
document.links[0].style.backgroundColor='#505050'
}
function function_link1(){
document.links['na'].style.backgroundColor='#900000'
}
function function_link2(){
document.links.na.style.backgroundColor='#800000'
}
function function_link3(){
document.links.item(0).style.backgroundColor='#100000'
}
</script>
</body>
</html>
Correcting teacher:滅絕師太Correction time:2019-03-02 09:19:46
Teacher's summary:學(xué)習(xí)到的知識點(diǎn)最好是結(jié)合案例練習(xí)哦!便于記憶!