????:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,
<!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> <style> #box{ width:150px; height:150px; background-color:red; } </style> </head> <body> <div id="box"> </div> <input type="button" onclick="color()" value="變色"> <input type="button" onclick="w()" value="變寬"> <input type="button" onclick="h()" value="變高"> <input type="button" onclick="block()" value="顯示"> <input type="button" onclick="none()" value="隱藏"> <script> var box = document.getElementById('box'); function color(){ box.style.backgroundColor="blue"; } function w(){ box.style.width="300px"; } function h(){ box.style.height="300px"; } function block(){ box.style.display="block"; } function none(){ box.style.display="none"; } </script> </body> </html>
通過getElementByID來獲取要操作的div,然后通過style進行更改樣式
?? ???:查無此人?? ??:2019-05-07 09:30:24
???? ??:完成的不錯。js語言很強大,要多練習(xí)。繼續(xù)加油