※ 소스

<!DOCTYPE html>
<html lang="ko">
  <head>
    <style>

      table {
        width: 100%;
      }
      div {
        position:absolute;
      }
      table, td, th,div {
        border : 1px solid black;
        border-collapse : collapse;
      };
    </style>
  </head>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>TEST</h1>
  <table id="tbl1">
  </table>
  <div id="loc"></div>
  <script>
    let tbl1 = document.getElementById("tbl1");
    let loc = document.getElementById("loc");
    let tr = "";
    for(let y=1;y<10;y++) {
      tr += "<tr>";
      for(let x=1;x<10;x++) {
        tr += "<td>" + y + x +"</td>";
      }
      tr += "</tr>";
    }
    tbl1.innerHTML = tr;
    document.onclick = function()
    {
      var winX = window.pageXOffset;
      var winY = window.pageYOffset;
      var el = event.srcElement;
      if(el.tagName.toLowerCase() != "td")
        return;
      var rect = el.getBoundingClientRect();
      loc.style.top = (winY + rect.top - 1) + "px";
      loc.style.left = (winX + rect.left - 1) + "px";
      loc.style.width = (rect.width) + "px";
      loc.style.height = (rect.height) + "px";
      loc.innerHTML = el.innerHTML;
    }
  </script>
</body>
</html>

 

728x90

+ Recent posts