['negative', '', 'positive'][Math.sign(article.total_comments.length) + 1]
import Vue from 'vue/dist/vue.esm.js'
import Vue from 'vue'
.row {
counter-reset: list -1;
}
.row a::before {
content: counter(list);
counter-increment: list;
}
.row a:first-child::before,
.row a:last-child::before {
content: "";
}
.row {
counter-reset: list 0;
}
.row a:not(:first-child, :last-child)::before {
content: counter(list);
counter-increment: list;
}
const inputSelector = '#kmOutMKAD';
const radioSelector = '[name="delivery"]';
const disabledValue = '1';
$(radioSelector).on('change', function() {
$(inputSelector).prop('disabled', this.value === disabledValue);
});
// или
const input = document.querySelector(inputSelector);
const radios = document.querySelectorAll(radioSelector);
const onChange = e => input.disabled = e.target.value === disabledValue;
radios.forEach(n => n.addEventListener('change', onChange));
$scope.edit = function(index) {
$scope.active = index;
};
ng-disabled="$index !== active"
const { classList: cl } = document.querySelector('#overlay');
const activeMenuClass = 'show-menu';
const matches = (el, ...selectors) => selectors.some(n => el.matches(n));
document.addEventListener('click', ({ target: t }) => {
if (matches(t, '#close-menu', 'li > a')) {
cl.remove(activeMenuClass);
} else if (matches(t, '#open-menu')) {
cl.add(activeMenuClass);
}
});
const
text = 'Sport',
str = 'port';
console.log(text.replace(new RegExp(`(${str})`, 'g'), '#$1#'));
или есть что-то оптимальней ?
text.replace(str, `#${str}#`)
. Правда, в отличие от регулярки - множественную замену так сделать не получится. switch(this.props.cardType) {
const Component = components[this.props.cardType];
return Component && <Component {...this.props} />;
const caesar = (str, offset) => Array
.from(str, n => String.fromCharCode(n.charCodeAt(0) + offset))
.join('');
const caesarTemplate = (title, offset) => `
<div class="caesar">
<textarea class="caesar-input" data-offset="${offset}"></textarea>
<hr>
<p>${title}: <span class="caesar-output"></span></p>
</div>
`;
document.addEventListener('input', ({ target: t }) => {
if (t.matches('.caesar-input')) {
const output = t.closest('.caesar').querySelector('.caesar-output');
output.innerHTML = caesar(t.value, +t.dataset.offset);
}
});
document.body.insertAdjacentHTML('beforeend', [
[ 'Шифр', 3 ],
[ 'Расшифровка', -3 ],
].map(n => caesarTemplate(...n)).join(''));
const text = (el => (el.innerHTML = html, el.innerText))(document.createElement('div'));
const text = new DOMParser().parseFromString(html, 'text/html').body.textContent;
const fragment = document.createRange().createContextualFragment(html);
const iter = document.createNodeIterator(fragment, NodeFilter.SHOW_TEXT);
const texts = [];
for (let n; n = iter.nextNode(); texts.push(n.nodeValue)) ;
v-for="o in getOptions2(index)"
на v-for="o in user.options"
; в обработчик change первого селекта передаёте текущий объект: @change="changeUser(user)"
, и соответственно, полученные данные кладёте в этот объект вместо options2 (их просто вырезаете):changeUser(user) {
fetch('https://jsonplaceholder.typicode.com/photos')
.then(r => r.json())
.then(d => this.$set(user, 'options', d));
},