main.js 727 B

123456789101112131415161718192021222324
  1. var table = document.createElement("table");
  2. table.setAttribute("cellpadding","15");
  3. table.setAttribute("border", "1");
  4. table.style.borderCollapse = "collapse";
  5. table.style.borderColor = "#ccc";
  6. document.body.appendChild(table);
  7. for (var i = 0; i < 9; i++) {
  8. table.appendChild(document.createElement("tr"));
  9. for (var j = 0; j < 9; j++) {
  10. table.children[i].appendChild(document.createElement("td"));
  11. table.children[i].children[j].innerHTML = (i + 1) * (j + 1);
  12. table.children[i].children[j].onmouseover = colorFuncOn;
  13. table.children[i].children[j].onmouseout = colorFuncOut;
  14. }
  15. }
  16. function colorFuncOn(){
  17. this.style.backgroundColor = "#ccc";
  18. }
  19. function colorFuncOut(){
  20. this.style.backgroundColor = "#fff";
  21. }