|
|
@@ -0,0 +1,28 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div id="box"></div>
|
|
|
+ <button id="btn">按钮</button>
|
|
|
+ <script>
|
|
|
+ // 获取元素
|
|
|
+ var box = document.getElementById("box");
|
|
|
+ var btn = document.getElementById("btn");
|
|
|
+
|
|
|
+ // 绑定事件
|
|
|
+ btn.onclick = function(){
|
|
|
+ // 控制样式 style 要控制样式的元素.style.样式名 = 样式值;
|
|
|
+ // 样式名称与css中的样式名称保持一致 值的部分为字符串
|
|
|
+ // 如果样式名称中出现"-",则要将"-"替换为驼峰命名法
|
|
|
+ // 其实js控制标签样式是通过style属性(内联样式)来实现的
|
|
|
+ box.style.height = "200px";
|
|
|
+ box.style.width = "200px";
|
|
|
+ box.style.backgroundColor = "red";
|
|
|
+ }
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|