-axios.post(baseUrlPost, {
+axios.post(baseUrlPost, formData, {
- method: 'post',
- body: formData,
headers: { 'Token': this.token, },
})
import { parse, format } from 'date-fns';
const getDate = (date) => format(
parse(date, 'yyyy-MM-dd HH:mm:ss', new Date()),
'MMM dd, yyyy'
);
<script src="main.js"></srcipt> -> <script src="main.js?1234567890"></srcipt>
button.addEventListener('click', (event) => {
event.preventDefault();
fetch('https://test.ru/?id=5&rating=5');
});
document.querySelector('.bx-soa-customer > .bx-soa-customer-field:last-child')?.classList.add('xyz');
document.querySelectorAll('.count-wrapper').forEach((wrapper) => {
const minusButton = wrapper.querySelector('.count-minus');
const plusButton = wrapper.querySelector('.count-plus');
const counterElement = wrapper.querySelector('.counter');
if (!minusButton || !plusButton || !counterElement) {
return;
}
let counter = Number(counterElement.textContent.trim()) || 0;
minusButton.addEventListener('click', (event) => {
event.preventDefault();
if (counter > 0) {
counter--;
}
counterElement.textContent = counter;
});
plusButton.addEventListener('click', (event) => {
event.preventDefault();
counter++;
counterElement.textContent = counter;
});
});
const string = '100 EUR * 10 +100 EUR - 300 EUR* 50 EUR';
const anotherString = string.replace(/\s*([-+/*])\s*/g, (match, char) => ` ${char} `);
console.log(anotherString);
const makeTree = (root) => {
const tree = {};
const step = (root, branch) => {
root.querySelectorAll(':scope > [class^="block"]').forEach((element, index) => {
const className = [...element.classList.values()].find(
(className) => className.startsWith('block')
) ?? element.className;
const key = `${className}_${index + 1}`;
branch[key] = {};
const control = element.querySelector(':scope > input');
if (control) {
branch[key].value = control.value;
}
step(element, branch[key]);
});
};
step(root, tree);
return tree;
};
const tree = makeTree(document.body);
console.log(tree);
const makeTree = (root) => {
const tree = {};
const step = (root, branch) => {
root.querySelectorAll(':scope > [class^="block"]').forEach((element, index) => {
const className = [...element.classList.values()].find(
(className) => className.startsWith('block')
) ?? element.className;
const key = `${className}_${index + 1}`;
const controls = element.querySelectorAll(':scope > input');
branch[key] = {
values: [...controls].reduce((acc, control) => {
if (control.id) {
acc[control.id] = control.value;
}
return acc;
}, {})
};
step(element, branch[key]);
});
};
step(root, tree);
return tree;
};
const tree = makeTree(document.body);
console.log(tree);
const pages = Array.from({ length: Math.ceil(reposCount / elementsCount) }, (_, i) => i + 1);
const pages = new Array(Math.ceil(reposCount / elementsCount)).fill(null).map((_, i) => i + 1);
function* range(from, to) {
for (let i = from; i <= to; i++) {
yield i;
}
}
const pages = [...range(1, Math.ceil(reposCount / elementsCount))];
encodeURIComponent(
decodeURIComponent('test+%0D%0Atest.+%0D%0ADtestestestes%0D%0Atesgdsger%0D%0A')
.replace(/\+?\r\n/g, '+\r\n')
)
if (${data.title} != 'null')
такое вообще работать не будет.null
, то можно решить проблему так:moviesEl.textContent = data.title ?? 'Another title';
cloneNode
не копирует события, о чём написано в документации.window.addEventListener('click', (event) => {
event.target.closest('.element__button')?.classList.toggle('element__button_active');
});
input
с типом checkbox
добавляете value
, причём у одинаковых значений value
должен совпадать. А дальше всё просто:$('input[type="checkbox"]').change(function (event) {
const checked = this.checked;
$(`input[type="checkbox"][value="${this.value}"]`).prop('checked', checked);
});
arr.map((item) => ({ ...item, averagePrice: item.finance / item.physicalVolume }));