9 июня 2021
Нет комментариев
$('input[type=number]').keyup(function(){ var max=parseInt($(this).attr('max')); var min=parseInt($(this).attr('min')); var val=$(this).val(); if(val<min){ $(this).val(min); } if(val>max){ $(this).val(max); } });
$('input[type=number]').keyup(function(){ var max=parseInt($(this).attr('max')); var min=parseInt($(this).attr('min')); var val=$(this).val(); if(val<min){ $(this).val(min); } if(val>max){ $(this).val(max); } });
try{ var result=JSON.parse(r); //... } catch(e){ }
$(".element").prop("clientWidth"); //или $(".element").prop("scrollWidth");
вместо
$('.element').width()
(function($){ $.widget("ui.onDelayedKeyup",{ _init:function(){ var self=this; $(this.element).keyup(function(){ if(typeof(window['inputTimeout'])!="undefined"){ window.clearTimeout(inputTimeout); } var handler=self.options.handler; window['inputTimeout']=window.setTimeout(function(){ handler.call(self.element) },self.options.delay); }); }, options:{ handler:$.noop(), delay:500 } }); })(jQuery); $('header .search input[type=text]').onDelayedKeyup({ handler:function(){ var string=$(this).val(); if(string.length>3){ //....... } }, delay:1000 });
function write_ini($array,$file){ $res=array(); foreach($array as $key=>$val){ if(is_array($val)){ $res[]="[$key]"; foreach($val as $skey=>$sval){ $res[]="$skey = ".(is_numeric($sval)?$sval:'"'.$sval.'"'); } } else{ $res[]="$key = ".(is_numeric($val)?$val:'"'.$val.'"'); } } safefilerewrite($file,implode("\r\n",$res)); } function safefilerewrite($fileName,$dataToSave){ if($fp=fopen($fileName,'w')){ $startTime=microtime(TRUE); do{ $canWrite=flock($fp,LOCK_EX); if(!$canWrite){ usleep(round(rand(0,100)*1000)); } } while((!$canWrite)and((microtime(TRUE)-$startTime)<5)); if($canWrite){ fwrite($fp,$dataToSave); flock($fp,LOCK_UN); } fclose($fp); } } $ini=parse_ini_file($_SERVER['DOCUMENT_ROOT']."/file.ini"); $ini['key']='value'; write_ini($ini,$_SERVER['DOCUMENT_ROOT']."/file.ini");
$('header nav ul li').hover(function(){ var li=$(this); this.timeout=window.setTimeout(function(){ li.addClass('hover'); },200) },function(){ $(this).removeClass('hover'); if(this.timeout){ window.clearTimeout(this.timeout); } });
function get_file_size($bytes){ if($bytes<1000*1024){ return number_format($bytes/1024,2)."KB"; } elseif($bytes<1000*1048576){ return number_format($bytes/1048576,2)."MB"; } elseif($bytes<1000*1073741824){ return number_format($bytes/1073741824,2)."GB"; } else{ return number_format($bytes/1099511627776,2)."TB"; } }