main.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //countrySelectTask
  2. let countrySelect = document.createElement('select')
  3. let citySelect = document.createElement('select')
  4. citySelect.id = "citySelect"
  5. countrySelect.id = "countrySelect"
  6. document.body.appendChild(countrySelect)
  7. document.body.appendChild(citySelect)
  8. fetch('https://raw.githubusercontent.com/russ666/all-countries-and-cities-json/master/countries.json')
  9. .then(res => res.json())
  10. .then(json => {
  11. let countrySelect = document.getElementById('countrySelect')
  12. let citySelect = document.getElementById('citySelect')
  13. function addOptions(select, arr) {
  14. for (let i = 0; i < arr.length; i++) {
  15. select.add(new Option(arr[i]))
  16. }
  17. }
  18. let countries = Object.keys(json)
  19. addOptions(countrySelect, countries)
  20. let defaultCities = json[countries[0]]
  21. addOptions(citySelect, defaultCities)
  22. countrySelect.addEventListener('change', function() {
  23. let cities = json[this.value]
  24. citySelect.length = 0
  25. addOptions(citySelect, cities)
  26. })
  27. console.log(json)
  28. })
  29. //tableMouseTask
  30. let table = document.createElement('table');
  31. document.body.appendChild(table)
  32. table.style.marginTop = '100px'
  33. for (let i = 0; i <= 9; i++){
  34. let tr = document.createElement('tr');
  35. for (let j = 0; j <= 9; j++){
  36. let td = document.createElement('td');
  37. td.style.padding = "5px";
  38. td.style.border = "2px solid black";
  39. if(i === 0) td.innerText = j;
  40. else if(j === 0) td.innerText = i;
  41. else td.innerHTML = i*j;
  42. tr.appendChild(td);
  43. td.onmouseover = function (event) {
  44. for (let i = 0; i < table.children.length; i++) {
  45. table.children[i].children[j].style.background = "lightgreen";
  46. }
  47. tr.style.background = "lightgreen"
  48. td.style.background = "lightgreen"
  49. td.style.boxShadow = "0px 5px 10px 2px rgba(34, 60, 80, 1)"
  50. tr.style.boxShadow = "0px 5px 10px 2px rgba(34, 60, 80, 1)"
  51. }
  52. td.onmouseout = function (event) {
  53. for (let i = 0; i < table.children.length; i++) {
  54. table.children[i].children[j].style.background = "";
  55. }
  56. tr.style.background = ""
  57. td.style.background = ""
  58. td.style.boxShadow = ""
  59. tr.style.boxShadow = ""
  60. }
  61. }
  62. table.appendChild(tr);
  63. }
  64. document.body.appendChild(table);