table2.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Table2</title>
  7. </head>
  8. <body>
  9. <script>
  10. function matrixTable() {
  11. var table = [];
  12. let tableInner = document.createElement("table")
  13. tableInner.setAttribute("border", "2")
  14. for(let i = 0; i < 10; i++) {
  15. var newrow = document.createElement("tr");
  16. table[i] = [];
  17. for(let j = 0; j < 10; j++){
  18. var newtd = document.createElement("td");
  19. newtd.onmouseover = function(){
  20. let coulum = document.getElementsByTagName("TD")
  21. for (let key of coulum){
  22. if (key.cellIndex == this.cellIndex){
  23. key.style = "background-color: #c4c0c0; border: 2px solid black; "
  24. }
  25. }
  26. this.parentElement.style = "background-color: #c4c0c0;"
  27. }
  28. newtd.onmouseout = function(){
  29. this.parentElement.style = "background-color: none; border: 2px solid black"
  30. let coulum = document.getElementsByTagName("TD")
  31. for (let key of coulum){
  32. if (key.cellIndex == this.cellIndex){
  33. key.style = "background-color: none; border: 2px solid black; width: 15px; height: 15px;"
  34. }
  35. }
  36. }
  37. newtd.style = "border: 2px solid black; width: 15px; height: 15px;"
  38. newtd.innerHTML = ((i) * j)
  39. let oneTd = newtd
  40. newrow.appendChild(oneTd)
  41. tableInner.appendChild(newrow)
  42. }
  43. document.body.appendChild(tableInner)
  44. }
  45. }
  46. matrixTable()</script>
  47. </body>
  48. </html>