發表文章

[Javascript] jQuery(function ($) { var $loading = $('‪#‎loading‬'); });

var $ = null; jQuery(function($){ var $loading = $("#loading"); });   var $ = null; jQuery(function(){ var $loading = $("#loading"); });   var $ = null; $(function(){ var $loading = $("#loading"); }); 避免$被其他人占用!

[Javascript] (function(global){})(this);

把 global 具體化成單一變數 這樣才能在不同環境底下都能調整、一致,不會需要大幅改動 這是javascript 的 immediate function 這邊的function 被宣告後立刻執行 叫做 immediate function 。 裡面的function (global) {} 就是宣告一個function 用() 包起來,再用後面的(this)去執行。 這邊的this 若在瀏覽器的console執行,會是window物件, 所以這邊的 immediate function 的global 就是window物件, 呼應tonyQ的概念,若在不同環境下執行 this不同,global變數也會不同。 <script src="jquery.1.11.0.js"></script> <script> window.$$ = jquery.noconflict(); (function($){...})($$); </script>

[PHP] CI 分頁 第一頁的URL

http://stackoverflow.com/questions/9989494/first-page-link-issue-in-codeigniter-pagination-library $config [ 'first_url' ] = 'method/page/1' ; $this -> pagination -> initialize ( $config );

jQuery 取得表單資料、單選 Radio 與多選 Checkbox 的方法/判斷 checkbox 是否選取,實現全選跟全部取消

全部選取/取消選取 checkbox $('#check-all').bind('click',function(){ var data_check = $(this).attr('data-check'); if(data_check === "0"){ $('input[name="place_ids[]"]').prop('checked',true); $('input[name="place_ids[]"]').parent().addClass('checked'); $(this).attr('data-check',1); $(this).html('取消全選'); }else{ $('input[name="place_ids[]"]').prop('checked',false); $('input[name="place_ids[]"]').parent().removeClass('checked'); $(this).attr('data-check',0); $(this).html('全部選取'); } }); 轉自  http://blog.miniasp.com/post/2011/04/27/jQuery-get-form-value-Checkbox-Radio.aspx var cbxVehicle = new Array(); $( 'input :checkbox :checked[name="vehicle"]' ).each( function (i) { cbxVehicle[i] = this .value; }); 另一個寫法是透過  .map()  將回傳值轉譯成為另一種陣列,如下: $( 'input :checkbo...

[linux] 將大量.gif副檔名改成.jpg

for file in *.gif; do mv "$file" "`basename $file .gif`.jpg" done

[PHP] 用程式將jpg丟給瀏覽器,Send jpg to browser ; 用CI將圖片縮圖後傳送到瀏覽器

/////////////////程式將jpg丟給瀏覽器開始///////////////// $img_path = '/var/www/html/XXX//img/a.jpg'; //成功後吐出圖片回傳 $type = 'image/jpeg'; header('Content-Type:'.$type); header('Content-Length: ' . filesize($img_path)); readfile($img_path); /////////////////程式將jpg丟給瀏覽器結束///////////////// /////////////////程式將jpg丟給瀏覽器開始///////////////// /*load library*/ $this->load->library('image_lib'); $this->load->library('net_util'); //必須在linux上安裝gd2 $this->img['image_library'] = 'gd2'; $this->img['maintain_ratio'] = TRUE; //縮圖使用 private function img_resize($source,$target,$width,$height,$crop=true,$img_name,$new_foler){ list($w,$h)=getimagesize($source); if ($w/$width>$h/$height){ $this->img['width'] = $w*($height/$h); $this->img['height'] = $height; $this->img['x_axis'] = ($this->img['width']-$width)/2; $this->img['y_axis'] = 0; }else{ $this->im...

MySQL筆記 IFNULL ,CASE WHEN

case when reference: http://jax-work-archive.blogspot.tw/2008/06/case-mysql-switch-if-else.html 必須在 SELECT,UPDATE,INSERT,DELETE 中 具有 switch 與 if else 兩種方式可用 #switch 的用法 SELECT CASE a WHEN 100 THEN a WHEN 50 THEN '0' ELSE '3' END FROM table; #if else 的用法 SELECT CASE WHEN a>100 THEN a WHEN a>50 THEN '0' ELSE '3' END FROM table; IFNULL reference: http://www.barryblogs.com/mysql-ifnull-if/ SELECT IFNULL(0, 1) ->0!=null,所以回傳0 SELECT IFNULL(1, 10) => 1!=null,所以回傳1 SELECT IFNULL(NULL, 'YES') =>若第一個參數為null時,回傳第二個參數,回傳YES