const data = $('.price')
.filter((i, n) => +n.value)
.closest('tr')
.find('input[type="hidden"]')
.get()
.map(n => n.value);
const data = Array
.from(document.querySelectorAll('.price'))
.filter(n => +n.value)
.map(n => n.closest('tr').querySelector('input[type="hidden"]').value);
const data = Array.prototype.reduce.call(
document.getElementsByClassName('price'),
(acc, { value: v, parentNode: { parentNode: tr } }) => (
+v && acc.push(tr.cells[0].children[0].value),
acc
),
[]
);
.xxx {
background: silver;
display: inline-flex;
justify-content: center;
align-items: center;
font-size: 24px;
padding: 0.3em 0.6em;
position: relative;
}
.xxx::before {
content: "";
width: 1em;
height: 1em;
left: -0.2em;
top: -0.2em;
background: orange;
position: absolute;
z-index: -1;
}
<span class="prev" data-step="-1">Prev</span>
<span class="next" data-step="+1">Next</span>
eq
позволяет указывать отрицательные индексы, которые используются для отсчёта позиции элемента начиная с конца; в случае чистого js надо будет добавить к сумме количество элементов, чтобы потенциальное отрицательное значение стало положительным, и при этом не изменился остаток от деления.const itemSelector = 'li';
const buttonSelector = '[data-step]';
const activeClass = 'active';
$(buttonSelector).click(function() {
const { step } = this.dataset;
const $items = $(itemSelector);
const $active = $items.filter(`.${activeClass}`);
$active.removeClass(activeClass);
$items.eq(($active.index() + +step) % $items.length).addClass(activeClass);
});
// или
const items = document.querySelectorAll(itemSelector);
let index = 0;
document.querySelectorAll(buttonSelector).forEach(n => {
n.addEventListener('click', onClick);
});
function onClick({ currentTarget: { dataset: { step } } }) {
items[index].classList.remove(activeClass);
index = (index + items.length + +step) % items.length;
items[index].classList.add(activeClass);
}
SELECT * FROM `table` WHERE `id` >= 76 AND `id` <= 936 AND`date` >= '2018-01-10' AND `date` <= '2018-02-01'
#или
SELECT * FROM `table` WHERE `date` BETWEEN '2018-09-10' AND '2018-11-10'
#или
SELECT * FROM `table` WHERE `date` IN ( '2018-09-10', '2018-11-10', '2018-10-10' )
SELECT DATE_FORMAT(`date`,"%d.%m.%Y") AS `date` FROM `table` WHERE id=1
<select id = 'shop'>
<option value = '0'>Фуршет</option>
<option value = '1'>Ашан</option>
<option value = '2'>Простор</option>
</select>
<select id = 'cathegory'></select>
$( 'select#shop' ).on( 'change', function() {
$.post( 'select_cathegory.php', {
data: { parent_id: this.value }, // поразумеваются, что значения для селекта #shop соответствуют parent_id в БД
success: function( response ) {
$( 'select#cathegory' ).html( response )
}
} )
} )
$result = mysql_query( 'SELECT * FROM objects WHERE parent_id = ' . $_POST[ 'parent_id' ] );
while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
echo ( '<option value = '. $row[ 'cathegory_id' ].'>'. $row[ 'cathegory_name' ] .'</option>' );
}
<select>
<optgroup label="Группа 1">
<option>Опция 1.1</option>
</optgroup>
<optgroup label="Группа 2">
<option>Опция 2.1</option>
<option>Опция 2.2</option>
</optgroup>
<optgroup label="Группа 3" disabled>
<option>Опция 3.1</option>
<option>Опция 3.2</option>
<option>Опция 3.3</option>
</optgroup>
</select>
class="subs"
, например.$('select').change(function() {
$('.subs [class*="sub"]')
.addClass('hidden')
.filter(`.sub${$(this).val()}`)
.removeClass('hidden');
});
// или
$('select').change(function(e) {
const index = ($(e.target).prop('selectedIndex') || Infinity) - 1;
this.addClass('hidden');
this.eq(index).removeClass('hidden');
}.bind($('.subs').children()));
document.querySelector('select').addEventListener('change', e => {
const cls = `sub${e.target.value}`;
document.querySelectorAll('.subs [class*="sub"]').forEach(n => {
n.classList.toggle('hidden', !n.classList.contains(cls));
});
});
// или
document.querySelector('select').addEventListener('change', e => {
const index = ~-e.target.selectedIndex;
Array.prototype.forEach.call(
document.querySelector('.subs').children,
(n, i) => n.classList.toggle('hidden', i !== index)
);
});