script.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. let table = document.createElement("table");
  3. for (let i = 0; i <= 9; i++) {
  4. let tr = document.createElement("tr");
  5. for (let x = 0; x <= 9; x++) {
  6. let td = document.createElement("td");
  7. td.style = `border: 1px solid grey; padding: 15px; color: black;`;
  8. let sum = i * x;
  9. if (sum == 0) {
  10. sum = i || x
  11. }
  12. td.innerText = sum
  13. tr.append(td);
  14. }
  15. table.append(tr);
  16. }
  17. document.body.append(table);
  18. function highlightCell() {
  19. let trSome = document.querySelectorAll("tr"),
  20. tdSome = document.querySelectorAll("td");
  21. tdSome.forEach(td => {
  22. td.addEventListener("mouseover", (e) => {
  23. console.log(e)
  24. td.style = `background-color: orange; color: white; padding: 15px; border: 1px solid grey; cursor: pointer`;
  25. });
  26. td.addEventListener("mouseout", (e) => {
  27. console.log(e)
  28. td.style = ` color: black; padding: 15px; border: 1px solid grey;`;
  29. })
  30. });
  31. }
  32. // highlightCell()
  33. function highlightRowColumn() {
  34. let trSome = document.querySelectorAll("tr"),
  35. tdSome = document.querySelectorAll("td");
  36. trSome.forEach(item => {
  37. item.addEventListener("mouseover", (e) => {
  38. let target = e.target,
  39. index = target.cellIndex,
  40. index2 = target.parentNode.rowIndex;
  41. trSome[index2].style.backgroundColor = "red";
  42. trSome.forEach(items => {
  43. items.children[index].style.backgroundColor = 'red';
  44. });
  45. });
  46. item.addEventListener("mouseout", (e) => {
  47. let target = e.target,
  48. index = target.cellIndex,
  49. index2 = target.parentNode.rowIndex;
  50. trSome[index2].style.backgroundColor = "white";
  51. trSome.forEach(item => {
  52. item.children[index].style.backgroundColor = '';
  53. })
  54. })
  55. });
  56. }
  57. // highlightRowColumn()