|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- <style type="text/css">
- .box1{
- width: 100px;
- height: 100px;
- background-color: orangered;
- }
- </style>
- </head>
- <body>
- <div class="box1"></div>
- <button type="button" id="color" onclick="gaiColor">点我更改颜色</button>
- <button type="button" id="color" onclick="getColor">点我获取颜色</button>
- </body>
- <script type="text/javascript">
- var a = document.getElementsByClassName("box1")[0];
- var getColor = function(){
- alert(a.currentstyle.backgroundColor);
- }
- var gaiColor = function(){
- a.style.backgroundColor = "red";
- }
- </script>
- </html>
复制代码
这两个获取样式和更改样式的按钮无效
a.currentstyle未定义 getColor执行会报错
button.onclick传字符串是eval执行 执行函数名需要加括号
|
|