main.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. fetch('https://raw.githubusercontent.com/russ666/all-countries-and-cities-json/master/countries.json')
  2. .then(res => res.json())
  3. .then(json => {
  4. let countrySelect = document.createElement("select");
  5. let citySelect = document.createElement("select");
  6. for (let countryName in json) {
  7. let countrySelectOption = document.createElement("option")
  8. countrySelectOption.innerText = countryName;
  9. countrySelect.append(countrySelectOption)
  10. }
  11. countrySelect.onchange = () => {
  12. citySelect.innerHTML = "";
  13. let cityName = json[countrySelect.value]
  14. for (let key in cityName) {
  15. let citySelectOption = document.createElement("option")
  16. citySelectOption.innerText = cityName[key];
  17. citySelect.append(citySelectOption)
  18. }
  19. }
  20. document.body.append(countrySelect);
  21. document.body.append(citySelect);
  22. })
  23. let table = document.createElement("table");
  24. for (let i = 0; i <= 9; i++) {
  25. let tr = document.createElement("tr");
  26. for (let j = 0; j <= 9; j++) {
  27. let td = document.createElement("td");
  28. if (i == 0 || j == 0) {
  29. td.innerText = i + j;
  30. } else {
  31. td.innerText = i * j;
  32. }
  33. tr.appendChild(td);
  34. td.onmouseover = function (event) {
  35. for (let i = 0; i < table.children.length; i++) { //перебор всех тр и покраска тд с определенным индексом
  36. table.children[i].children[j].style.background = "yellow";
  37. }
  38. tr.style.background = "red" //красим строку
  39. td.style.background = "orange"; //красим саму ячейку
  40. }
  41. td.onmouseout = function (event) {
  42. for (let i = 0; i < table.children.length; i++) {
  43. table.children[i].children[j].style.background = "";
  44. }
  45. tr.style.background = ""
  46. td.style.background = "";
  47. }
  48. }
  49. table.appendChild(tr);
  50. }
  51. document.body.appendChild(table);
  52. table.style.float = "left";