用循环将三个DIV变成红色
2015-05-03 22:46
302 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>用循环将三个DIV变成红色</title> <style> #outer{width:330px;height:100px;margin:10px auto;} #outer div{float:left;width:100px;height:100px;margin:0 5px;background:black;} </style> <script> window.onload = function () { var oDiv = document.getElementById("outer").getElementsByTagName("div"); var oBtn = document.getElementsByTagName("button")[0]; oBtn.onclick = function () { for(var i = 0; i < oDiv.length; i++) oDiv[i].style.background = "red"; } } </script> </head> <body> <center><button>点击将DIV变成红色</button></center> <div id="outer"> <div></div> <div></div> <div></div> </div> </body> </html>
相关文章推荐
- 用循环将三个Div变成红色
- Ferris教程学习笔记:js示例2.3 用循环将三个DIV变成红色
- fgm实例练习笔记-1.4用循环将三个Div变成红色
- javascript小练习—点击将DIV变成红色(通过for循环遍历)
- 用中断使屏幕变成红色的
- lua for循环的三个条件在第一次循环前一次性求值
- “只用赋值、加1、循环三个操作实现一个减1的运算。
- vue 里面通过v-for循环出来多个相同样式的div,根据index值给每个div添加不同的id名
- Codeforces Round #260 (Div. 2) B. Fedya and Maths(循环结)
- 循环灯控制器,该控制器控制红、绿、黄三个发光管循环发亮(VHDL语言)
- 有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC
- 用DIV+javascript实现首尾相连循环滚动效果(兼容firefox)
- android studio 所有项目文件名都变成了红色
- Android studio中R变成红色
- C#中添加三个线程同时启动执行某一方法,并依次调用某方法中的循环打印输。
- 三个线程循环打印ABC10次的几种解决方法
- 产品展示会用到的表格循环之(div+css)
- 三个js循环的关键字示例(for与while)
- Myeclipese建立servelet时出现带有javax.servlet.http.HttpServlet;变成了红色的解决方法
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) D. Delivery Bears 二分+网络流(循环写二分,否则T。。。)