const tableSelector = 'таблица ваша, так что вам и виднее, какой у неё селектор';
const text = 'Материал';
$(`${tableSelector} tbody tr:contains(${text})`).hide();
for (const { rows } of document.querySelector(tableSelector).tBodies) {
for (const tr of rows) {
for (const td of tr.cells) {
if (td.innerText.includes(text)) {
tr.style.display = 'none';
break;
}
}
}
}
.hidden {
display: none;
}
document.querySelectorAll(`${tableSelector} tbody tr`).forEach(tr => {
tr.classList.toggle('hidden', ~tr.textContent.indexOf(text));
});
data: () => ({
value: '',
}),
computed: {
style() {
return {
width: `${20 + this.value.length * 10}px`,
};
},
},
<input v-model="value" :style="style">
function Ship(x, y) {
this.x = x;
this.y = y;
}
function PlayerShip(x, y) {
Ship.call(this, x, y);
this.petrol = 100;
}
<i class="icon-arrow-down" @click="updateCount(good, -1)"></i>
<i class="icon-arrow-top" @click="updateCount(good, 1)"></i>
methods: {
updateCount(good, change) {
good.count = Math.max(0, good.count + change);
},
},
Копипаста кода из документации результата не даёт
data: () => ({
numShow: 0,
...
computed: {
itemsToShow() {
return this.items.slice(0, this.numShow);
},
...
methods: {
showNext() {
this.numShow = Math.min(this.items.length, this.numShow + 1);
},
hidePrev() {
this.numShow = Math.max(0, this.numShow - 1);
},
...
<transition-group
@after-enter="showNext"
@after-leave="hidePrev"
...
>
<div
v-for="(n, i) in itemsToShow"
:key="n.id"
...
>
...
methods: {
run() {
this.numShow += ({
0: 1,
[this.items.length]: -1,
})[this.numShow] || 0;
},
...
export default class UserForm ...
data: () => ({
types: [
{ id: null, name: 'Все' },
{ id: ..., name: '...' },
{ id: ..., name: '...' },
...
],
active: null,
...
<button v-for="n in types" @click="active = n.id">{{ n.name }}</button>
<!-- или -->
<select v-model="active">
<option v-for="n in types" :value="n.id">{{ n.name }}</option>
</select>
<!-- или -->
<label v-for="n in types">
<input type="radio" name="type" :value="n.id" v-model="active">
{{ n.name }}
</label>
computed: {
filteredItems() {
const { items, active } = this;
return active ? items.filter(n => n.type === active) : items;
},
...
<tr v-for="(n, i) in filteredItems">
...
const classes = $buttons.get().map(n => n.dataset.set);
$buttons.click(function() {
$('.current').removeClass('current');
$(this).addClass('current');
$blocks.removeClass(classes.join(' ')).addClass(this.dataset.set);
});
let currentClass = null;
$buttons.click(function() {
$('.current').removeClass('current');
$(this).addClass('current');
const newClass = this.dataset.set;
$blocks.removeClass(currentClass).addClass(newClass);
currentClass = newClass;
});
const parent = document.querySelector('здесь селектор элемента с абзацами');
const el = document.querySelector('а здесь - элемента, который хотите перенести');
const last = parent.lastElementChild;
// или
const last = parent.querySelector(':scope > :last-child');
// или
const last = parent.children[parent.children.length - 1];
// или
const [ last ] = Array.prototype.slice.call(parent.children, -1);
last.before(el);
// или
last.insertAdjacentElement('beforebegin', el);
// или
last.replaceWith(el, last);
// или
parent.insertBefore(el, last);
if ($days_in_this_week < 8) {
if ($days_in_this_week > 1) {
function drawCalendar($year, $month) {
$date = DateTime::createFromFormat('Y-m-d', "$year-$month-1");
$day = DateInterval::createFromDateString('1 day');
$weekdays = [ 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс' ];
do {
$date->sub($day);
} while ($date->format('w') !== '1');
$days = [];
for ($i = 0; $i < 42; $i++, $date->add($day)) {
$m = intval($date->format('m'));
$days[] = $m === $month ? intval($date->format('d')) : ' ';
}
return "
<table cellpadding=\"5\" cellspacing=\"5\" border=\"1\">
<thead>
<tr class=\"b-calendar__row\">".implode('', array_map(function($n) { return "
<th class=\"b-calendar__head\">$n</th>"; }, $weekdays))."
</tr>
</thead>
<tbody>".implode('', array_map(function($week) { return "
<tr class=\"b-calendar__row\">".implode('', array_map(function($n, $i) { return "
<td class=\"b-calendar__day ".($i > 4 ? 'b-calendar__weekend' : '')."\">
$n
</td>"; }, $week, array_keys($week)))."
</tr>"; }, array_chunk($days, 7)))."
</tbody>
</table>";
}
echo drawCalendar(2018, 1);
class App extends React.Component {
state = {
data: [
'#088A85', '#0B2F3A', '#0B0B3B', '#2A0A29', '#B4045F',
'#FA58F4', '#A9BCF5', '#58FA82', '#A9F5F2', '#CED8F6',
].map((n, i) => ({
id: i + 1,
color: n,
title: `block #${i}`,
opened: false,
})),
}
updateItem(index, key, val) {
const data = [...this.state.data];
data[index][key] = val;
this.setState({ data });
}
render() {
return (
<div>{this.state.data.map(({ id, color, title, opened }, i) => (
<div key={id}>
<div
className="square"
style={{ backgroundColor: color }}
onClick={() => this.updateItem(i, 'opened', !opened)}
>
<p>{title}</p>
</div>
{opened &&
<div>
<input
value={color}
onChange={e => this.updateItem(i, 'color', e.target.value)}
/>
<input
value={title}
onChange={e => this.updateItem(i, 'title', e.target.value)}
/>
</div>}
</div>))}
</div>
)
}
}
.square {
width: 100px;
height: 100px;
}
.services_minus
. То есть, при клике на плюс не происходит вообще ничего, а минус - количество будет уменьшаться, и сразу же увеличиваться обратно..next('.services_nomer')
следует заменить на.closest('.services_button_block').find('.services_nomer')
parseInt
. Или можно оформить как одно выражение и поиск элемента с количеством и его обновление, передав в метод text
функцию, которая примет текущее содержимое элемента и должна будет вернуть новое:$('.services_minus').click(function() {
$(this)
.closest('.services_button_block')
.find('.services_nomer')
.text((i, text) => Math.max(0, text - 1));
});
$('.services_plus').click(function() {
$(this)
.closest('.services_button_block')
.find('.services_nomer')
.text((i, text) => +text + 1);
});
почему после возвращения из рекурсивного вызова i=3 а не 2?
2
. Хотя должно быть 1
.i
является глобальной. А то, что вообще работает - потому что строгий режим не включался. Погуглите, что происходит при присваивании значения необъявленной переменной.if (numbers[i].length) {
function flat(arr) {
const result = [];
for (const n of arr) {
if (n instanceof Array) {
result.push(...flat(n));
} else {
result.push(n);
}
}
return result;
}
// или
const flat = arr =>
Array.prototype.concat.apply(
[],
arr.map(n => Array.isArray(n) ? flat(n) : n)
);