abstrakt:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<ul id="ul">
<li id="1">列表項(xiàng)01</li>
<li>列表項(xiàng)02</li>
<li class="green">列表項(xiàng)03</li>
<li class="green">列表項(xiàng)04</li>
<li class="large">列表項(xiàng)05</li>
</ul>
<form action="get">
用戶名:<input type="text" name="username"><br>
</form>
<script>
document.getElementById('1').style.backgroundColor = 'red'; //根據(jù)id屬性獲取元素
document.getElementsByName('username')[0].style.backgroundColor = 'yellow'; //根據(jù)name屬性獲取元素,獲得的是一個(gè)數(shù)組
document.getElementsByTagName('li')[1].style.backgroundColor = 'blue'; //根據(jù)標(biāo)簽名獲得元素
document.getElementsByClassName('green')[0].style.backgroundColor = 'green'; //根據(jù)class類獲得元素,獲得也是一個(gè)數(shù)組
document.querySelector('.large').style.backgroundColor='orange'; //根據(jù)css選擇器獲得元素,獲得也是一個(gè)數(shù)組
</script>
</body>
</html>
Korrigierender Lehrer:滅絕師太Korrekturzeit:2019-02-27 09:15:15
Zusammenfassung des Lehrers:完成的不錯(cuò),建議使用谷歌和火狐瀏覽器哦!