<input name="firstname" ...
.const formData = new FormData(formElement);
после e.preventDefault();
.const formData = new FormData(e.target);
.const formData = new FormData(this);
. Поясните это поведение
g
- то есть, ищутся все совпадения с шаблоном, а не только первое. Вы вызываете метод test - совпадение найдено, круто. Вызываете снова - поиск начинается не с начала, а с того места, где он был окончен в прошлый раз. Разумеется, в этот раз ничего не найдено. Вызываете test в третий раз - снова всё хорошо, потому что в прошлый раз совпадения кончились, поиск снова выполняется с начала строки.посоветуйте как вывернуть так, чтобы нормально отрабатывало
g
.hyper.lastIndex = 0;
. Разумеется, этот вариант является говнокодом. data: () => ({
newPhone: {},
...
}),
<input v-model="newPhone.name">
<input v-model="newPhone.ssd">
addPhone() {
this.phones.push(this.newPhone);
this.newPhone = {};
},
const select = document.querySelector('.table__select');
// или
const [ select ] = document.getElementsByClassName('table__select');
select.innerHTML = arr.map(n => `<option>${n}</option>`).join('');
// или
select.append(...arr.map(n => new Option(n)));
// или
for (const n of arr) {
select.appendChild(document.createElement('option'));
select.lastChild.text = n;
}
// или
for (let i = 0; i < arr.length; i++) {
const option = document.createElement('option');
option.textContent = arr[i];
select.insertAdjacentElement('beforeend', option);
}
const arr = [
[ 2, 7, 2 ],
[ 2, 5, 4 ],
[ 2, 1, 5 ],
[ 3, 1, 2 ],
];
const [ val, iRow, iCol ] = arr
.map((n, i) => n.reduce((min, m, j) => min[0] <= m ? min : [ m, i, j ], [ Infinity, -1 ]))
.reduce((min, n) => min[0] <= n[0] ? min : n);
const arr = [
[ 2, 7, 2, [ 5, [ 4, [ 3 ], 2 ] ] ],
[ 2, 5, [ 2, 6, 5, 2 ], 4 ],
[ 2, 1, [ [ [ 9, 0, 1 ], [ [ [ 1 ] ] ], -1 ] ], 5 ],
[ 3, 1, 2 ],
];
const minElemWithIndex = arr =>
arr.reduce((min, n, i) => {
const m = n instanceof Array
? minElemWithIndex(n)
: [ n, [] ];
m[1].unshift(i);
return m[0] < min[0] ? m : min;
}, [ Infinity, [] ]);
const [ val, indices ] = minElemWithIndex(arr);
$.ajax({
type: 'POST',
dataType: 'json',
url: 'https://api.novaposhta.ua/v2.0/json/',
data: JSON.stringify({
modelName: 'Address',
calledMethod: 'searchSettlements',
methodProperties: {
CityName: 'ки',
Limit: 555
},
apiKey: 'f11a8e14401ddcf710f7195b4ebe358c'
}),
headers: {
'Content-Type': 'application/json'
},
xhrFields: {
withCredentials: false
},
success: function(texts) {
console.log(texts);
},
});
<ul>
<li
v-for="(n, i) in items"
:data-rel="`ex-${i + 1}`"
@click="active = i"
>item #{{ i + 1 }}</li>
</ul>
<div
v-if="active !== null"
@mouseleave="active = null"
>{{ items[active] }}</div>
data() {
return {
active: null,
items: [
'hello, world!!',
'fuck the world',
'fuck everything'
]
}
}
onChange(data) {
$('input[name="sum"]').val(data.from);
}
И как поступить, если слайдера например два.
onChange(data) {
data.input
.closest('селектор блоков со слайдерами')
.find('селектор инпутов, в которые надо копировать значения')
.val(data.from);
}
data: () => ({
blocks: [
{
template: '<div><ul><li v-for="n in data" v-html="n"></li></ul></div>',
data: [
'<h2>Заголовок 1</h2><p>какой-то текст 1</p>',
'<h2>Заголовок 2</h2><p>какой-то текст 2</p>',
],
},
{
template: '<div><h3 v-for="color in data" :style="{ color }">{{ color }}</h3></div>',
data: [ 'red', 'green', 'blue' ],
},
{
template: '<div><p v-for="i in data">{{ i }}</p></div>',
data: 4,
},
],
}),
Vue.component('block-component', {
props: [ 'template', 'data' ],
computed: {
compiled() {
return Vue.compile(this.template);
},
},
render() {
return this.compiled.render.call(this);
},
});
<block-component v-for="n in blocks" v-bind="n"></block-component>
margin-left
и margin-top
.display: inline-block;
.30%
и 50%
, например.