zoukankan      html  css  js  c++  java
  • for-计算元素和坐标

    运用for循环计算元素和坐标,做出这样一个小玩意出来

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     5 <title>无标题文档</title>
     6 
     7 <style>
     8 div { 50px; height:50px; background:red; position:absolute; top:0; left:0; font-size:30px; text-align:center; line-height:50px; color:#fff; }
     9 </style>
    10 
    11 <script>
    12 window.onload = function (){
    13     var aDiv = document.getElementsByTagName('div');
    14     
    15     for( var i=0; i<11; i++ ){
    16         document.body.innerHTML += '<div>' + i + '</div>';
    17     }
    18     
    19     for( var i=0; i<aDiv.length; i++ ){
    20         aDiv[i].style.left = 10 + i*50 + 'px';
    21         aDiv[i].style.top = 10 + i*50 + 'px';
    22     }
    23     
    24 };
    25 </script>
    26 </head>
    27 
    28 <body>
    29 
    30 
    31 
    32 </body>
    33 </html>
    示例代码
  • 相关阅读:
    UESTC
    Education Round 8 A
    Gym
    Gym
    hdoj 1159 Common Subsequence
    UVA
    UESTC
    51Nod 1068 Bash游戏 V3 (这规律不好找)
    51Nod 1066 Bash游戏
    51Nod 1002 数塔取数问题
  • 原文地址:https://www.cnblogs.com/123wyy123wyy/p/6910867.html
Copyright © 2011-2022 走看看