<form>
<select name="dropdown">
<option value="opt_1">Opt 1</option>
<option value="opt_2" selected>Opt 2</option>
<option value="opt_3">Opt 3</option>
</select>
<input type="text" name="some_text" value="Text">
<input type="checkbox" name="checkbox_1" value="checked" checked>
<input type="checkbox" name="checkbox_2" value="not checked">
<input type="radio" name="radio_group" value="not checked">
<input type="radio" name="radio_group" value="checked" checked>
<input type="radio" name="radio_group" value="not checked">
<textarea name="bigtext">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit, ab tempora voluptate assumenda!</textarea>
</form>
<div id="demo"></div>
var result = [];
[].forEach.call(document.querySelector('form').elements, function(el) {
if (['checkbox', 'radio'].indexOf(el.type) === -1 || el.checked) {
result.push(el.name + ' > ' + el.value);
}
});
demo.innerHTML = result.join('<br>');
$.ajaxSetup({
beforeSend: function(jqXHR, settings) {
console.log(settings.data);
}
});
$.ajaxSetup({
beforeSend: function(jqXHR, settings) {
if ('http://site.com'.indexOf(settings.url) !== -1) {
console.log(settings.data);
}
}
});
var root = $('<div class="districts" />'),
box, child;
for (var k in data) {
if (data.hasOwnProperty(k)) {
box = $('<div class="popup" />');
child = $('<div calss="' + k + '" />').appendTo(box);
for (var i in data[k].img) {
if (data[k].img.hasOwnProperty(i)) {
$('<img src="/img/' + k + '/' + data[k].img[i].name + '.png" />').appendTo(child);
}
}
box.appendTo(root);
}
}
$('body').append(root); // выводим на экран
// (!) при этом, выводим один раз, а не мучаем DOM на каждой итерации
<div class="districts">
<div class="popup">
<div calss="test">
<img src="/img/test/01.png">
<img src="/img/test/02.png">
<img src="/img/test/03.png">
</div>
</div>
<div class="popup">
<div calss="test2">
<img src="/img/test2/01.png">
<img src="/img/test2/02.png">
<img src="/img/test2/03.png">
</div>
</div>
<div class="popup">
<div calss="test3">
<img src="/img/test3/01.png">
<img src="/img/test3/02.png">
<img src="/img/test3/03.png">
</div>
</div>
<div class="popup">
<div calss="test4">
<img src="/img/test4/01.png">
<img src="/img/test4/02.png">
<img src="/img/test4/03.png">
</div>
</div>
</div>
<div id="slider"></div>
<p>
<input id="inp" type="number" max="100">
</p>
var factor = 4, // число, на которое необходимо умножать значение
inp = $("#inp").attr('min', factor),
slider = $('#slider').slider({
min: factor,
max: 100,
range: 'min',
value: 0,
step: factor,
slide: function(event, ui) {
var num = ui.value / factor;
inp.val(ui.value);
}
});
inp.on('input', function() {
var num = factor * $(this).val();
slider.slider('value', num);
});
<div>
<label>
<input type="hidden" name="stand[3]">3
</label>
<label>
<input type="hidden" name="stand[1]">1
</label>
<label>
<input type="hidden" name="stand[2]">2
</label>
</div>
<div>
<img src="http://automated-testing.info/images/emoji/apple/smile.png" alt="">
<img src="http://radar.techcabal.com/images/emoji/apple/grin.png" alt="">
<img src="http://www.stickees.com/files/emoticons/emojicons/148-happy-smile.png" alt="">
</div>
<button>GO!</button>
var but = $('button'),
inp = $('[name^="stand"]');
$('img').draggable({
revert: 'invalid'
});
$('label').droppable({
accept: function() {
return $.trim($('input', this).val()) === '';
},
tolerance: 'fit',
drop: function(e, ui) {
$('input', this).val(ui.draggable.attr('src'));
$(ui.draggable).draggable('disable');
var hasEmpty = inp.filter(function() {
return $.trim($(this).val()) === '';
}).length;
but[hasEmpty ? 'hide' : 'show']();
}
});
but.on('click', function() {
$.ajax({
url: '/echo/html/',
type: 'POST',
data: inp,
success: function(data) {}
});
});
print_r($_POST['stand']);
Array (
[1] => path/to/img1.png
[2] => path/to/img2.png
[3] => path/to/img3.png
)
<button cart_reload='["cart_items","item_col_out"]'>Single quotes</button>
<!-- или -->
<button cart_reload="["cart_items","item_col_out"]">Entity</button>
var myselect = document.getElementById('myselect'),
selIndx = 0;
myselect.addEventListener('focus', function() {
selIndx = this.selectedIndex;
this.options[this.options.length - 1].selected = true;
}, false);
myselect.addEventListener('blur', function() {
this.selectedIndex = selIndx;
}, false);
myselect.addEventListener('change', function() {
selIndx = this.selectedIndex;
this.blur();
}, false);
var sel = document.querySelector('select');
sel.options[0].textContent = 'от ' + sel.options[0].textContent;
sel.addEventListener('change', function(){
var curIndex = this.selectedIndex;
[].forEach.call(this.options,function(opt, i){
if(i === curIndex) {
opt.textContent = 'от ' + opt.textContent;
} else {
opt.textContent = opt.textContent.replace(/[^\d]+/,'');
}
});
});
Или чуть покороче, изменив цикл[].forEach.call(this.options,function(opt, i){
opt.textContent = i === curIndex ? 'от ' + opt.textContent : opt.textContent.replace(/[^\d]+/,'');
});
$('#first').insertAfter('#second');
// или аналогично
// $('#second').insertBefore('#first');
init()
, после this.setup()
дописываем this.showFirstLastLetter()
showFirstLastLetter()
showFirstLastLetter: function(){
this.guessLetterInput.val(this.wrd.letters[0].letter);
this.guessForm.trigger('submit');
this.guessLetterInput.val(this.wrd.letters[this.wrd.totalLetters-1].letter);
this.guessForm.trigger('submit');
},
;(function($){
$.fn.fadeInDelay = function(){
var init = function(){
$(this).hide().delay($(this).data('delay')).fadeIn();
};
return this.each(init);
};
}(jQuery));
$('div').fadeInDelay();
$(function() {
if ($(window).width() < 768) {
var iconset = $('.iconset-phone');
$(window).on('scroll', function() {
iconset[$(this).scrollTop() > 0 ? 'slideUp' : 'slideDown']();
});
}
});
<div data-hint="Какой-то текст к div-у 1">1</div>
<div data-hint="Какой-то текст к div-у 2">2</div>
<div data-hint="Какой-то текст к div-у 3">3</div>
<div id="hint"></div>
div[data-hint] {
display: inline-block;
width: 150px;
height: 150px;
margin: 15px;
border: 1px solid #900;
}
#hint {
display: none;
position: absolute;
padding: 5px;
margin: -15px auto auto 10px;
border-radius: 5px;
box-shadow: 0 0 1px 2px rgba(0,0,0,.3);
background-color: #fff;
z-index: 100500;
}
var hint = $('#hint');
$('div[data-hint]').on({
mouseenter: function(){
hint.text($(this).data('hint')).show();
},
mouseleave: function(){
hint.hide();
},
mousemove: function(e){
hint.css({top: e.pageY, left: e.pageX});
}
});
var elH = horizontal.offsetHeight,
elTop = horizontal.offsetTop,
winH = window.innerHeight,
factor = horizontal.scrollWidth / (elH * 2 + winH);
window.addEventListener('scroll', function (e) {
var elPosTop = horizontal.getBoundingClientRect().top + elH,
elPosBot = horizontal.getBoundingClientRect().bottom - elH;
if ((elPosTop >= 0) && (elPosBot <= winH)) {
var dE = document.documentElement,
top = (this.pageYOffset || dE.scrollTop) - (dE.clientTop || 0);
horizontal.scrollLeft = Math.abs(elTop - winH - top) * factor;
}
}, false);