Это можно сравнить с тем, что ты учишь, как класть стену, но не понимаешь, как вообще строятся здания, по каким принципам, из чего, как и т.д.
for (const [ k, v ] of new URLSearchParams(url.replace(/.*\?/, ''))) {
document.querySelector(`#${k}`).value = v;
}
url
.slice(url.indexOf('?') + 1)
.split('&')
.map(n => n.split('='))
.forEach(n => document.getElementById(n[0]).value = n[1]);
const data = [...url.split('?').pop().matchAll(/([^&]+)=([^&]*)/g)];
for (let i = 0; i < data.length; i++) {
document.querySelector(`[id="${data[i][1]}"]`).value = data[i][2];
}
.flex-inner > li > label {
margin-left: 10px;
line-height: 50px;
}
.flex-inner > li > input {
position: relative;
top: 1.6px;
cursor: pointer;
}
{"2019-12-22":[{"dt":1577048400,"main":{"temp":-21.94,"feels_like":-26.97,"temp_min":-22.46,"temp_max":-21.94,"pressure":1018,"sea_level":1018,"grnd_level":1013,"humidity":99,"temp_kf":0.52},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":34},"wind":{"speed":1.97,"deg":139},"sys":{"pod":"n"},"dt_txt":"2019-12-22 21:00:00"}],
...}
let wd = {};
data.list.map(e => {
let dt = e.dt_txt.split(" ")[0];
if(typeof(wd[dt])!="undefined") {
wd[dt].push(e);
} else {
wd[dt] = [];
}
});
console.log(JSON.stringify(wd));
let iconUrl="";
let wdate = ""; // переменная состояния
function forecastTemplate (localData) {
let s = "";
if (localData.dt_txt.split(" ")[0] != wdate) {
wdate = localData.dt_txt.split(" ")[0];
s += `
<tr><td colspan=2>${wdate}</td>
`;
}
s += `
<tr>
<td>
<div class="flex">
<div>
<span>${localData.dt_txt.split(" ")[1]}<span>
</div>
<div>
<img src="${iconUrl}${localData.weather[0].icon}@2x.png">
</div>
</div>
</td>
<td>
<div class="flex">
<div>
<span class="temp">${localData.main.temp}℃</span>
</div>
<div>
<span class="description">${localData.weather[0].description}</span>
</div>
</div>
<div class="flex">
<div>
<span>wind: ${localData.wind.speed} m/s,</span>
</div>
<div>
<span>clouds: ${localData.clouds.all}%,</span>
</div>
<div>
<span>pressure: ${localData.main.pressure} hPa</span>
</div>
</div>
</td>
</tr>`
return s
}
let html = "";
document.body.innerHTML = `<table>${data.list.map(forecastTemplate).join("")}</table>`;
for (var prop in deliveryDatesObj) {
var value = deliveryDatesObj[prop];
///......
}
for (var prop in deliveryDatesObj) {
var value = deliveryDatesObj[prop];
deliveryDates.options[deliveryDates.options.length] = new Option(value, prop );
}
stateSel.options[stateSel.options.length] = new Option(state, state);
stateSel.onchange = function () { countySel.length = 1; // remove all options bar first citySel.length = 1; // remove all options bar first if (this.selectedIndex < 1) return; // done for (var county in stateObject[this.value]) { countySel.options[countySel.options.length] = new Option(county, county); } }
//document.addEventListener('DOMContentLoaded', () => { //faster
window.addEventListener('load', () => {
//Set localStorage
let el = {
userName: document.getElementById("nameField"),
userEmail: document.getElementById("emailField"),
userDateOfBirth: document.getElementById("dateField"),
};
//Wnen out of focus - set localStorage
let addFocusEvent =
s => el[s].addEventListener("focusout",
e => localStorage[s] = el[s].value);
for (let k in el) addFocusEvent(k);
//Get localStorage
for (let k in el) el[k].value = localStorage[k] || "";
});