parseInt('') будет NaN.0 вместо мусорных результатов парсинга, замените parseInt($(this).val()) на parseInt($(this).val()) || 0.
<span>hello, world!!... fuck the world... fuck everything</span>body {
margin: 0;
background: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
span {
color: red;
font-size: 24px;
font-family: monospace;
}
.xxx {
display: inline-block;
min-width: 10px;
transition: all 0.2s;
transform: scale(1);
}
.hidden {
opacity: 0;
transform: scale(30);
}function show(el) {
el.innerHTML = Array
.from(el.innerText, n => `<span class="xxx hidden">${n}</span>`)
.join('');
el.querySelectorAll('span').forEach((n, i) => {
setTimeout(() => n.classList.remove('hidden'), 100 * i);
});
}
show(document.querySelector('span'));
const getText = el => el.textContent;
// или
const getText = el => el.innerText;
// или
const getText = el => el.innerHTML;
// или
const getText = el => el.lastChild.nodeValue;
// или
const getText = el => el.childNodes[0].data;const getValue = text => text.match(/"(.*?)"/)[1];
// или
const getValue = text => text.split('"').slice(-2).shift();
// или
const getValue = text => text.replace(/^.*?"|"[^"]*$/g, '');
//
const getValue = text => `${/(?<=")[^"]+/.exec(text)}`;
// или
const getValue = text =>
JSON.parse(text.slice(-~text.indexOf('['), text.indexOf(']')));document.querySelectorAll('li button').forEach(function(n) {
n.addEventListener('click', this);
}, e => console.log(getValue(getText(e.target))));
// или
document.querySelector('ul').addEventListener('click', ({ target: t }) => {
if (t.tagName === 'BUTTON') {
console.log(getValue(getText(t)));
}
});
data: () => ({
items: Array(10).fill(null),
...<ul>
<li v-for="(n, i) in items" :style="index < i || { color: n }">
{{ i }}
</li>
</ul>methods: {
next(color) {
const { index, items } = this;
this.index = index === items.length - 1 ? 0 : index + 1;
items.splice(this.index, 1, color);
},
...data: () => ({
colors: [ 'red', 'lime', 'blue', 'orange', 'magenta', 'aqua', 'yellow' ],
...<button v-for="c in colors" @click="next(c)">{{ c }}</button>
headerObj.offsetTopconst frame = document.getElementsByTagName('iframe')[0];
$data = array_reduce(explode('/', $str), function($acc, $n) {
list($key, $values) = explode('-is-', $n);
$acc[$key] = explode('-or-', $values);
return $acc;
}, []);
const sums = arr.reduce((acc, n, i) => (
(i & 1) || acc.push(0),
acc[acc.length - 1] += n,
acc
), []);
// или
const sums = arr.reduce(
(acc, n, i) => (acc[i / 2 | 0] += n, acc),
Array(Math.ceil(arr.length / 2)).fill(0)
);
// или
const sums = Array.from(
{ length: arr.length / 2 + arr.length % 2 },
(n, i) => arr[i * 2] + (arr[i * 2 + 1] || 0)
);
// или
const sums = eval(`[${arr}]`.replace(/(\d+),(\d+)/g, '$1+$2'));const result = sums.join(' ');
// или
const result = sums.reduce((acc, n) => acc + (acc && ' ') + n, '');
// или
const result = ''.concat(...sums.flatMap((n, i) => i ? [ ' ', n ] : n));
// или
const result = String(sums).replace(/,/g, ' ');
<span id="wrong"> в шаблоне компонента - а если экземпляров компонента будет несколько?), путаетесь с операторами - использовали побитовое ИЛИ там, где должно было быть логическое. Может, стоит подождать с vue и подтянуть основы?