17 января 2017
Нет комментариев
function resizeInput(){ $(this).css('width',($(this).val().length*7.5)+'px'); } $(document).ready(function(){ $('.inputs input').each(resizeInput); });
function resizeInput(){ $(this).css('width',($(this).val().length*7.5)+'px'); } $(document).ready(function(){ $('.inputs input').each(resizeInput); });
$.fn.toggleText=function(t1,t2){ if(this.text()==t1)this.text(t2); else this.text(t1); return this; };
Пример использования:
$(document).ready(function(){ $(".shch").click(function(){ $(this).toggleText('+','-'); $(this).closest('li').children('ul').slideToggle(); return false; }); });
В примере задержка 200мс перед появлением блока
$('.cart_module').delay(200).fadeIn();
Решаем проблему с тем, что атрибут required не работает в мобильных safari (возможно еще где-то).
Обновлено:
$('form').on('submit',function(){ var required=$(this).find('[required="required"]'); var error=false; $(required).each(function(){ if($(this).val()==''){ $(this).css('border-color','#e03c42'); if(!error){ $(this).focus(); } error=true; } else{ $(this).css('border-color','#ffffff'); } }); if(error){ return false; } });
Прежний вариант:
$('form').on('submit',function(){ var required=$(this).find('[required="required"]'); var error=false; for(var i=0;i<=(required.length-1);i++){ if(required[i].value==''){ required[i].style.backgroundColor='rgb(255,155,155)'; error=true; } else{ required[i].style.backgroundColor='white'; } } if(error){ return false; } });
Оригинал с http://stackoverflow.com/questions/10664356/html5-form-element-required-on-ipad-iphone-doesnt-work
$('form').submit(function(){ var required=$('[required="true"]'); var error=false; for(var i=0;i<=(required.length-1);i++){ if(required[i].value==''){ required[i].style.backgroundColor='rgb(255,155,155)'; error=true; } } if(error){ return false; } });
Или на основе чего-нибудь из (http://stackoverflow.com/questions/23261301/required-attribute-not-work-in-safari-browser):
$("form").submit(function(e){ var ref=$(this).find("[required]"); $(ref).each(function(){ if($(this).val()==''){ alert("Required field should not be blank."); $(this).focus(); e.preventDefault(); return false; } }); return true; });
$('#idForm').click(function(e){ e.preventDefault(); var sendModalForm=true; $('[required]').each(function(){ if($(this).val()==''){ sendModalForm=false; alert("Required field should not be blank."); $('.error-message').show(); } }); if(sendModalForm){ $('#idForm').submit(); } });
$(".datepicker").datepicker(); $.datepicker.regional['ru']={ closeText:'Закрыть', prevText:'<Пред', nextText:'След>', currentText:'Сегодня', monthNames:['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'], monthNamesShort:['Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек'], dayNames:['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'], dayNamesShort:['вск','пнд','втр','срд','чтв','птн','сбт'], dayNamesMin:['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], weekHeader:'Нед', dateFormat:'dd.mm.yy', firstDay:1, isRTL:false, showMonthAfterYear:false, yearSuffix:'' }; $.datepicker.setDefaults($.datepicker.regional['ru']);
@keyframes trambling-animation{ 0%,50%,100%{ transform:rotate(0deg); } 10%,30%{ transform:rotate(-10deg); } 20%,40%{ transform:rotate(10deg); } } .trambling{ animation:1.2s ease-in-out 0s normal none infinite running trambling-animation; }
LESS с поддержкой старых браузеров
.transform(@transform){ -moz-transform:@transform; -ms-transform:@transform; -webkit-transform:@transform; -o-transform:@transform; transform:@transform; } .animation(@animation){ -webkit-animation:@animation; -moz-animation:@animation; -o-animation:@animation; animation:@animation; } @keyframes trambling-animation{ 0%,50%,100%{ .transform(rotate(0deg)); } 10%,30%{ .transform(rotate(-10deg)); } 20%,40%{ .transform(rotate(10deg)); } } .trambling{ .animation(1.2s ease-in-out 0s normal none infinite running trambling-animation); }
Или используйте jquery плагин jRumble:
https://jackrugile.com/jrumble/
function delete_cookie(name){ document.cookie=name+'=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; }
или более сложный вариант с возможностью создания и чтения cookie, если это нужно:
function createCookie(name,value,days){ if(days){ var date=new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires="; expires="+date.toGMTString(); } else var expires=""; document.cookie=name+"="+value+expires+"; path=/"; } function readCookie(name){ var nameEQ=name+"="; var ca=document.cookie.split(';'); for(var i=0;i<ca.length;i++){ var c=ca[i]; while(c.charAt(0)==' ')c=c.substring(1,c.length); if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name){ createCookie(name,"",-1); }
http://stackoverflow.com/questions/2144386/javascript-delete-cookie